diff --git a/third_party/libosmium/CHANGELOG.md b/third_party/libosmium/CHANGELOG.md index e9377b656..2ca6518c8 100644 --- a/third_party/libosmium/CHANGELOG.md +++ b/third_party/libosmium/CHANGELOG.md @@ -13,6 +13,32 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [2.6.0] - 2016-02-04 + +### Added + +- The new handler osmium::handler::CheckOrder can be used to check that a + file is properly ordered. +- Add new method to build OSM nodes, ways, relations, changesets, and areas + in buffers that wraps the older Builder classes. The new code is much easier + to use and very flexible. There is no documentation yet, but the tests in + `test/t/builder/test_attr.cpp` can give you an idea how it works. +- Add util class to get memory usage of current process on Linux. + +### Changed + +- New Buffer memory management speeds up Buffer use, because it doesn't clear + the memory unnecessarily. + +### Fixed + +- osmium::Box::extend() function now ignores invalid locations. +- Install of external library headers. +- Check way has at least one node before calling `is_closed()` in area + assembler. +- Declaration/definition of some friend functions was in the wrong namespace. + + ## [2.5.4] - 2015-12-03 ### Changed @@ -234,7 +260,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). Doxygen (up to version 1.8.8). This version contains a workaround to fix this. -[unreleased]: https://github.com/osmcode/libosmium/compare/v2.5.4...HEAD +[unreleased]: https://github.com/osmcode/libosmium/compare/v2.6.0...HEAD +[2.6.0]: https://github.com/osmcode/libosmium/compare/v2.5.4...v2.6.0 [2.5.4]: https://github.com/osmcode/libosmium/compare/v2.5.3...v2.5.4 [2.5.3]: https://github.com/osmcode/libosmium/compare/v2.5.2...v2.5.3 [2.5.2]: https://github.com/osmcode/libosmium/compare/v2.5.1...v2.5.2 diff --git a/third_party/libosmium/CMakeLists.txt b/third_party/libosmium/CMakeLists.txt index 0764915ea..73394674e 100644 --- a/third_party/libosmium/CMakeLists.txt +++ b/third_party/libosmium/CMakeLists.txt @@ -24,8 +24,8 @@ set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel;Dev;Cover project(libosmium) set(LIBOSMIUM_VERSION_MAJOR 2) -set(LIBOSMIUM_VERSION_MINOR 5) -set(LIBOSMIUM_VERSION_PATCH 4) +set(LIBOSMIUM_VERSION_MINOR 6) +set(LIBOSMIUM_VERSION_PATCH 0) set(LIBOSMIUM_VERSION "${LIBOSMIUM_VERSION_MAJOR}.${LIBOSMIUM_VERSION_MINOR}.${LIBOSMIUM_VERSION_PATCH}") @@ -459,7 +459,7 @@ endif() install(DIRECTORY include/osmium DESTINATION include) if(INSTALL_GDALCPP) - install(include/gdalcpp.hpp DESTINATION include) + install(FILES include/gdalcpp.hpp DESTINATION include) endif() if(INSTALL_PROTOZERO) @@ -467,7 +467,7 @@ if(INSTALL_PROTOZERO) endif() if(INSTALL_UTFCPP) - install(include/utf8.hpp DESTINATION include) + install(FILES include/utf8.h DESTINATION include) install(DIRECTORY include/utf8 DESTINATION include) endif() diff --git a/third_party/libosmium/include/osmium/area/assembler.hpp b/third_party/libosmium/include/osmium/area/assembler.hpp index 87feea29e..1d9b0df6b 100644 --- a/third_party/libosmium/include/osmium/area/assembler.hpp +++ b/third_party/libosmium/include/osmium/area/assembler.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -753,7 +753,7 @@ namespace osmium { for (size_t offset : members) { if (!std::strcmp(memit->role(), "inner")) { const osmium::Way& way = in_buffer.get(offset); - if (way.is_closed() && way.tags().size() > 0) { + if (!way.nodes().empty() && way.is_closed() && way.tags().size() > 0) { auto d = std::count_if(way.tags().begin(), way.tags().end(), filter()); if (d > 0) { osmium::tags::KeyFilter::iterator way_fi_begin(filter(), way.tags().begin(), way.tags().end()); diff --git a/third_party/libosmium/include/osmium/area/detail/node_ref_segment.hpp b/third_party/libosmium/include/osmium/area/detail/node_ref_segment.hpp index aab5b8fa3..7c1555a33 100644 --- a/third_party/libosmium/include/osmium/area/detail/node_ref_segment.hpp +++ b/third_party/libosmium/include/osmium/area/detail/node_ref_segment.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/detail/proto_ring.hpp b/third_party/libosmium/include/osmium/area/detail/proto_ring.hpp index 162e2896d..59478dc63 100644 --- a/third_party/libosmium/include/osmium/area/detail/proto_ring.hpp +++ b/third_party/libosmium/include/osmium/area/detail/proto_ring.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/detail/segment_list.hpp b/third_party/libosmium/include/osmium/area/detail/segment_list.hpp index 289ecf0c9..29eec589c 100644 --- a/third_party/libosmium/include/osmium/area/detail/segment_list.hpp +++ b/third_party/libosmium/include/osmium/area/detail/segment_list.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/multipolygon_collector.hpp b/third_party/libosmium/include/osmium/area/multipolygon_collector.hpp index 2881597b0..81a28b24b 100644 --- a/third_party/libosmium/include/osmium/area/multipolygon_collector.hpp +++ b/third_party/libosmium/include/osmium/area/multipolygon_collector.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/problem_reporter.hpp b/third_party/libosmium/include/osmium/area/problem_reporter.hpp index 4ae4bb23d..1dde85ba9 100644 --- a/third_party/libosmium/include/osmium/area/problem_reporter.hpp +++ b/third_party/libosmium/include/osmium/area/problem_reporter.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/problem_reporter_exception.hpp b/third_party/libosmium/include/osmium/area/problem_reporter_exception.hpp index 7c9a5e393..abadd9653 100644 --- a/third_party/libosmium/include/osmium/area/problem_reporter_exception.hpp +++ b/third_party/libosmium/include/osmium/area/problem_reporter_exception.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/problem_reporter_ogr.hpp b/third_party/libosmium/include/osmium/area/problem_reporter_ogr.hpp index 68fae3bb8..d58fe559c 100644 --- a/third_party/libosmium/include/osmium/area/problem_reporter_ogr.hpp +++ b/third_party/libosmium/include/osmium/area/problem_reporter_ogr.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/area/problem_reporter_stream.hpp b/third_party/libosmium/include/osmium/area/problem_reporter_stream.hpp index b6a004cdf..ffd94a605 100644 --- a/third_party/libosmium/include/osmium/area/problem_reporter_stream.hpp +++ b/third_party/libosmium/include/osmium/area/problem_reporter_stream.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/builder/attr.hpp b/third_party/libosmium/include/osmium/builder/attr.hpp new file mode 100644 index 000000000..d9831c28f --- /dev/null +++ b/third_party/libosmium/include/osmium/builder/attr.hpp @@ -0,0 +1,877 @@ +#ifndef OSMIUM_BUILDER_ATTR_HPP +#define OSMIUM_BUILDER_ATTR_HPP + +/* + +This file is part of Osmium (http://osmcode.org/libosmium). + +Copyright 2013-2016 Jochen Topf and others (see README). + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace osmium { + + namespace builder { + + namespace detail { + +#ifdef _MSC_VER + // workaround for bug in MSVC + + template + struct is_handled_by; + + template + struct is_handled_by { + static constexpr bool value = false; + }; + + template + struct is_handled_by { + static constexpr bool value = std::is_base_of::value || + is_handled_by::value; + }; + + template + struct are_all_handled_by; + + template + struct are_all_handled_by { + static constexpr bool value = std::is_base_of::value; + }; + + template + struct are_all_handled_by { + static constexpr bool value = std::is_base_of::value && + are_all_handled_by::value; + }; +#else + // True if Predicate matches for none of the types Ts + template class Predicate, typename... Ts> + struct static_none_of : std::is_same::type...>, + std::tuple::type..., std::false_type>> + {}; + + // True if Predicate matches for all of the types Ts + template class Predicate, typename... Ts> + struct static_all_of : std::is_same::type...>, + std::tuple::type..., std::true_type>> + {}; + + // True if THandler is derived from the handler for at least one of the types in TTypes + template + struct is_handled_by { + template + using HasHandler = std::is_base_of; + + static constexpr bool value = !static_none_of::value; + }; + + // True if THandler is derived from the handlers of all the types in TTypes + template + struct are_all_handled_by { + template + using HasHandler = std::is_base_of; + + static constexpr bool value = static_all_of::value; + }; +#endif + + + // Wraps any type, so that we can derive from it + template + struct type_wrapper { + + using type = TType; + + TType value; + + constexpr explicit type_wrapper(const TType& v) : + value(v) { + } + + }; // struct type_wrapper + + // Small wrapper for begin/end iterator + template + struct iterator_wrapper { + + using type = TType; + + TType first; + TType last; + + constexpr iterator_wrapper(TType begin, TType end) : + first(begin), + last(end) {} + + constexpr TType begin() const { + return first; + } + + constexpr TType end() const { + return last; + } + + }; // struct iterator_wrapper + + + struct entity_handler {}; + struct object_handler; + struct node_handler; + struct tags_handler; + struct nodes_handler; + struct members_handler; + struct changeset_handler; + struct discussion_handler; + struct ring_handler; + + } // namespace detail + +#define OSMIUM_ATTRIBUTE(_handler, _name, _type) \ + struct _name : public osmium::builder::detail::type_wrapper<_type> { \ + using handler = osmium::builder::detail::_handler; + +#define OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(_handler, _name, _type) \ + OSMIUM_ATTRIBUTE(_handler, _name, _type) \ + constexpr explicit _name(std::add_const<_type>::type& value) : \ + type_wrapper(value) {} \ + } + +#define OSMIUM_ATTRIBUTE_ITER(_handler, _name) \ + template \ + struct _name : public osmium::builder::detail::iterator_wrapper { \ + using handler = osmium::builder::detail::_handler; \ + constexpr _name(TIterator first, TIterator last) : \ + osmium::builder::detail::iterator_wrapper(first, last) {} \ + } + + namespace attr { + + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(object_handler, _id, osmium::object_id_type); + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(object_handler, _version, osmium::object_version_type); + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(entity_handler, _uid, osmium::user_id_type); + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(entity_handler, _cid, osmium::changeset_id_type); + + OSMIUM_ATTRIBUTE(object_handler, _deleted, bool) + constexpr explicit _deleted(bool value = true) noexcept : + type_wrapper(value) {} + }; + + OSMIUM_ATTRIBUTE(object_handler, _visible, bool) + constexpr explicit _visible(bool value = true) noexcept : + type_wrapper(value) {} + }; + + OSMIUM_ATTRIBUTE(object_handler, _timestamp, osmium::Timestamp) + constexpr explicit _timestamp(const osmium::Timestamp& value) noexcept : + type_wrapper(value) {} + constexpr explicit _timestamp(time_t value) noexcept : + type_wrapper(osmium::Timestamp{value}) {} + constexpr explicit _timestamp(uint32_t value) noexcept : + type_wrapper(osmium::Timestamp{value}) {} + explicit _timestamp(const char* value) : + type_wrapper(osmium::Timestamp{value}) {} + explicit _timestamp(const std::string& value) : + type_wrapper(osmium::Timestamp{value}) {} + }; + + OSMIUM_ATTRIBUTE(node_handler, _location, osmium::Location) + constexpr explicit _location(const osmium::Location& value) noexcept : + type_wrapper(value) {} + explicit _location(double lat, double lon) : + type_wrapper(osmium::Location{lat, lon}) {} + }; + + OSMIUM_ATTRIBUTE(entity_handler, _user, const char*) + constexpr explicit _user(const char* val) noexcept : + type_wrapper(val) {} + explicit _user(const std::string& val) noexcept : + type_wrapper(val.c_str()) {} + }; + + using pair_of_cstrings = std::pair; + using pair_of_strings = std::pair; + + class member_type { + + osmium::item_type m_type; + osmium::object_id_type m_ref; + const char* m_role; + + public: + + constexpr member_type(osmium::item_type type, osmium::object_id_type ref, const char* role = "") noexcept : + m_type(type), + m_ref(ref), + m_role(role) { + } + + constexpr osmium::item_type type() const noexcept { + return m_type; + } + + constexpr osmium::object_id_type ref() const noexcept { + return m_ref; + } + + constexpr const char* role() const noexcept { + return m_role; + } + + }; // class member_type + + class comment_type { + + osmium::Timestamp m_date; + osmium::user_id_type m_uid; + const char* m_user; + const char* m_text; + + public: + + constexpr comment_type(osmium::Timestamp date, osmium::user_id_type uid, const char* user, const char* text) noexcept : + m_date(date), + m_uid(uid), + m_user(user), + m_text(text) { + } + + constexpr osmium::Timestamp date() const noexcept { + return m_date; + } + + constexpr osmium::user_id_type uid() const noexcept { + return m_uid; + } + + constexpr const char* user() const noexcept { + return m_user; + } + + constexpr const char* text() const noexcept { + return m_text; + } + + }; // class comment_type + + namespace detail { + + OSMIUM_ATTRIBUTE_ITER(tags_handler, tags_from_iterator_pair); + + OSMIUM_ATTRIBUTE_ITER(nodes_handler, nodes_from_iterator_pair); + + OSMIUM_ATTRIBUTE_ITER(members_handler, members_from_iterator_pair); + + OSMIUM_ATTRIBUTE_ITER(discussion_handler, comments_from_iterator_pair); + + OSMIUM_ATTRIBUTE_ITER(ring_handler, outer_ring_from_iterator_pair); + OSMIUM_ATTRIBUTE_ITER(ring_handler, inner_ring_from_iterator_pair); + + } // namespace detail + + OSMIUM_ATTRIBUTE(tags_handler, _tag, pair_of_cstrings) + explicit _tag(const pair_of_cstrings& value) noexcept : + type_wrapper(value) {} + explicit _tag(const std::pair& value) : + type_wrapper(pair_of_cstrings{value.first, value.second}) {} + explicit _tag(const std::pair& value) : + type_wrapper(pair_of_cstrings{value.first, value.second}) {} + explicit _tag(const std::pair& value) : + type_wrapper(pair_of_cstrings{value.first, value.second}) {} + explicit _tag(const pair_of_strings& value) : + type_wrapper(std::make_pair(value.first.c_str(), value.second.c_str())) {} + explicit _tag(const char* key, const char* val) : + type_wrapper(std::make_pair(key, val)) {} + explicit _tag(const std::string& key, const std::string& val) : + type_wrapper(std::make_pair(key.c_str(), val.c_str())) {} + }; + + template + inline constexpr detail::tags_from_iterator_pair _tags(TTagIterator first, TTagIterator last) { + return detail::tags_from_iterator_pair(first, last); + } + + template + inline detail::tags_from_iterator_pair _tags(const TContainer& container) { + return detail::tags_from_iterator_pair(std::begin(container), std::end(container)); + } + + using tag_ilist = std::initializer_list>; + inline detail::tags_from_iterator_pair _tags(const tag_ilist& container) { + return detail::tags_from_iterator_pair(std::begin(container), std::end(container)); + } + + + + OSMIUM_ATTRIBUTE(nodes_handler, _node, osmium::NodeRef) + constexpr explicit _node(osmium::object_id_type value) noexcept : + type_wrapper(NodeRef{value}) {} + constexpr explicit _node(const NodeRef& value) noexcept : + type_wrapper(value) {} + }; + + template + inline constexpr detail::nodes_from_iterator_pair _nodes(TIdIterator first, TIdIterator last) { + return detail::nodes_from_iterator_pair(first, last); + } + + template + inline detail::nodes_from_iterator_pair _nodes(const TContainer& container) { + return detail::nodes_from_iterator_pair(std::begin(container), std::end(container)); + } + + using object_id_ilist = std::initializer_list; + inline detail::nodes_from_iterator_pair _nodes(const object_id_ilist& container) { + return detail::nodes_from_iterator_pair(std::begin(container), std::end(container)); + } + + using node_ref_ilist = std::initializer_list; + inline detail::nodes_from_iterator_pair _nodes(const node_ref_ilist& container) { + return detail::nodes_from_iterator_pair(std::begin(container), std::end(container)); + } + + + OSMIUM_ATTRIBUTE(members_handler, _member, member_type) + constexpr explicit _member(const member_type& value) noexcept : + type_wrapper(value) {} + constexpr explicit _member(osmium::item_type type, osmium::object_id_type id) noexcept : + type_wrapper({type, id}) {} + constexpr explicit _member(osmium::item_type type, osmium::object_id_type id, const char* role) noexcept : + type_wrapper({type, id, role}) {} + explicit _member(osmium::item_type type, osmium::object_id_type id, const std::string& role) noexcept : + type_wrapper({type, id, role.c_str()}) {} + explicit _member(const osmium::RelationMember& member) noexcept : + type_wrapper({member.type(), member.ref(), member.role()}) {} + }; + + template + inline constexpr detail::members_from_iterator_pair _members(TMemberIterator first, TMemberIterator last) { + return detail::members_from_iterator_pair(first, last); + } + + template + inline detail::members_from_iterator_pair _members(const TContainer& container) { + return detail::members_from_iterator_pair(std::begin(container), std::end(container)); + } + + using member_ilist = std::initializer_list; + inline detail::members_from_iterator_pair _members(const member_ilist& container) { + return detail::members_from_iterator_pair(std::begin(container), std::end(container)); + } + + + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(changeset_handler, _num_changes, osmium::num_changes_type); + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(changeset_handler, _num_comments, osmium::num_comments_type); + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(changeset_handler, _created_at, osmium::Timestamp); + OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR(changeset_handler, _closed_at, osmium::Timestamp); + + OSMIUM_ATTRIBUTE(discussion_handler, _comment, comment_type) + constexpr explicit _comment(const comment_type& value) noexcept : + type_wrapper(value) {} + explicit _comment(const osmium::ChangesetComment& comment) noexcept : + type_wrapper({comment.date(), comment.uid(), comment.user(), comment.text()}) {} + }; + + template + inline constexpr detail::comments_from_iterator_pair _comments(TCommentIterator first, TCommentIterator last) { + return detail::comments_from_iterator_pair(first, last); + } + + template + inline detail::comments_from_iterator_pair _comments(const TContainer& container) { + return detail::comments_from_iterator_pair(std::begin(container), std::end(container)); + } + + using comment_ilist = std::initializer_list; + inline detail::comments_from_iterator_pair _comments(const comment_ilist& container) { + return detail::comments_from_iterator_pair(std::begin(container), std::end(container)); + } + + + template + inline constexpr detail::outer_ring_from_iterator_pair _outer_ring(TIdIterator first, TIdIterator last) { + return detail::outer_ring_from_iterator_pair(first, last); + } + + template + inline detail::outer_ring_from_iterator_pair _outer_ring(const TContainer& container) { + return detail::outer_ring_from_iterator_pair(std::begin(container), std::end(container)); + } + + using object_id_ilist = std::initializer_list; + inline detail::outer_ring_from_iterator_pair _outer_ring(const object_id_ilist& container) { + return detail::outer_ring_from_iterator_pair(std::begin(container), std::end(container)); + } + + using node_ref_ilist = std::initializer_list; + inline detail::outer_ring_from_iterator_pair _outer_ring(const node_ref_ilist& container) { + return detail::outer_ring_from_iterator_pair(std::begin(container), std::end(container)); + } + + template + inline constexpr detail::inner_ring_from_iterator_pair _inner_ring(TIdIterator first, TIdIterator last) { + return detail::inner_ring_from_iterator_pair(first, last); + } + + template + inline detail::inner_ring_from_iterator_pair _inner_ring(const TContainer& container) { + return detail::inner_ring_from_iterator_pair(std::begin(container), std::end(container)); + } + + using object_id_ilist = std::initializer_list; + inline detail::inner_ring_from_iterator_pair _inner_ring(const object_id_ilist& container) { + return detail::inner_ring_from_iterator_pair(std::begin(container), std::end(container)); + } + + using node_ref_ilist = std::initializer_list; + inline detail::inner_ring_from_iterator_pair _inner_ring(const node_ref_ilist& container) { + return detail::inner_ring_from_iterator_pair(std::begin(container), std::end(container)); + } + + + } // namespace attr + +#undef OSMIUM_ATTRIBUTE_ITER +#undef OSMIUM_ATTRIBUTE_WITH_CONSTRUCTOR +#undef OSMIUM_ATTRIBUTE + + namespace detail { + + struct changeset_handler : public entity_handler { + + template + static void set_value(osmium::Changeset&, const TDummy&) noexcept { + } + + static void set_value(osmium::Changeset& changeset, attr::_cid id) noexcept { + changeset.set_id(id.value); + } + + static void set_value(osmium::Changeset& changeset, attr::_num_changes num_changes) noexcept { + changeset.set_num_changes(num_changes.value); + } + + static void set_value(osmium::Changeset& changeset, attr::_num_comments num_comments) noexcept { + changeset.set_num_comments(num_comments.value); + } + + static void set_value(osmium::Changeset& changeset, attr::_created_at created_at) noexcept { + changeset.set_created_at(created_at.value); + } + + static void set_value(osmium::Changeset& changeset, attr::_closed_at closed_at) noexcept { + changeset.set_closed_at(closed_at.value); + } + + static void set_value(osmium::Changeset& changeset, attr::_uid uid) noexcept { + changeset.set_uid(uid.value); + } + + }; + + struct object_handler : public entity_handler { + + template + static void set_value(osmium::OSMObject&, const TDummy&) noexcept { + } + + static void set_value(osmium::OSMObject& object, attr::_id id) noexcept { + object.set_id(id.value); + } + + static void set_value(osmium::OSMObject& object, attr::_version version) noexcept { + object.set_version(version.value); + } + + static void set_value(osmium::OSMObject& object, attr::_visible visible) noexcept { + object.set_visible(visible.value); + } + + static void set_value(osmium::OSMObject& object, attr::_deleted deleted) noexcept { + object.set_deleted(deleted.value); + } + + static void set_value(osmium::OSMObject& object, attr::_timestamp timestamp) noexcept { + object.set_timestamp(timestamp.value); + } + + static void set_value(osmium::OSMObject& object, attr::_cid changeset) noexcept { + object.set_changeset(changeset.value); + } + + static void set_value(osmium::OSMObject& object, attr::_uid uid) noexcept { + object.set_uid(uid.value); + } + + }; // object_handler + + struct node_handler : public object_handler { + + using object_handler::set_value; + + static void set_value(osmium::Node& node, attr::_location location) noexcept { + node.set_location(location.value); + } + + }; // node_handler + + template + inline void add_basic(TBuilder& builder, const TArgs&... args) noexcept { + (void)std::initializer_list{ + (THandler::set_value(builder.object(), args), 0)... + }; + } + + // ============================================================== + + template + inline constexpr const char* get_user(const attr::_user& user, const TArgs&...) noexcept { + return user.value; + } + + inline constexpr const char* get_user() noexcept { + return ""; + } + + template + inline constexpr typename std::enable_if::value, const char*>::type + get_user(const TFirst&, const TRest&... args) noexcept { + return get_user(args...); + } + + template + inline void add_user(TBuilder& builder, const TArgs&... args) { + builder.add_user(get_user(args...)); + } + + // ============================================================== + + struct tags_handler { + + template + static void set_value(TagListBuilder&, const TDummy&) noexcept { + } + + static void set_value(TagListBuilder& builder, const attr::_tag& tag) { + builder.add_tag(tag.value); + } + + template + static void set_value(TagListBuilder& builder, const attr::detail::tags_from_iterator_pair& tags) { + for (const auto& tag : tags) { + builder.add_tag(tag); + } + } + + }; // struct tags_handler + + struct nodes_handler { + + template + static void set_value(WayNodeListBuilder&, const TDummy&) noexcept { + } + + static void set_value(WayNodeListBuilder& builder, const attr::_node& node_ref) { + builder.add_node_ref(node_ref.value); + } + + template + static void set_value(WayNodeListBuilder& builder, const attr::detail::nodes_from_iterator_pair& nodes) { + for (const auto& ref : nodes) { + builder.add_node_ref(ref); + } + } + + }; // struct nodes_handler + + struct members_handler { + + template + static void set_value(RelationMemberListBuilder&, const TDummy&) noexcept { + } + + static void set_value(RelationMemberListBuilder& builder, const attr::_member& member) { + builder.add_member(member.value.type(), member.value.ref(), member.value.role()); + } + + template + static void set_value(RelationMemberListBuilder& builder, const attr::detail::members_from_iterator_pair& members) { + for (const auto& member : members) { + builder.add_member(member.type(), member.ref(), member.role()); + } + } + + }; // struct members_handler + + struct discussion_handler { + + template + static void set_value(ChangesetDiscussionBuilder&, const TDummy&) noexcept { + } + + static void set_value(ChangesetDiscussionBuilder& builder, const attr::_comment& comment) { + builder.add_comment(comment.value.date(), comment.value.uid(), comment.value.user()); + builder.add_comment_text(comment.value.text()); + } + + template + static void set_value(ChangesetDiscussionBuilder& builder, const attr::detail::comments_from_iterator_pair& comments) { + for (const auto& comment : comments) { + builder.add_comment(comment.date(), comment.uid(), comment.user()); + builder.add_comment_text(comment.text()); + } + } + + }; // struct discussion_handler + + struct ring_handler { + + template + static void set_value(AreaBuilder&, const TDummy&) noexcept { + } + + template + static void set_value(AreaBuilder& parent, const attr::detail::outer_ring_from_iterator_pair& nodes) { + OuterRingBuilder builder(parent.buffer(), &parent); + for (const auto& ref : nodes) { + builder.add_node_ref(ref); + } + } + + template + static void set_value(AreaBuilder& parent, const attr::detail::inner_ring_from_iterator_pair& nodes) { + InnerRingBuilder builder(parent.buffer(), &parent); + for (const auto& ref : nodes) { + builder.add_node_ref(ref); + } + } + + }; // struct ring_handler + + // ============================================================== + + template + inline typename std::enable_if::value>::type + add_list(osmium::builder::Builder&, const TArgs&...) noexcept { + } + + template + inline typename std::enable_if::value>::type + add_list(osmium::builder::Builder& parent, const TArgs&... args) { + TBuilder builder(parent.buffer(), &parent); + (void)std::initializer_list{ + (THandler::set_value(builder, args), 0)... + }; + } + + struct any_node_handlers : public node_handler, public tags_handler {}; + struct any_way_handlers : public object_handler, public tags_handler, public nodes_handler {}; + struct any_relation_handlers : public object_handler, public tags_handler, public members_handler {}; + struct any_area_handlers : public object_handler, public tags_handler, public ring_handler {}; + struct any_changeset_handlers : public changeset_handler, public tags_handler, public discussion_handler {}; + + } // namespace detail + + + /** + * Create a node using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the node will be added. + * @param args The attributes of the node. + * @returns The position in the buffer where this node was added. + */ + template + inline size_t add_node(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_node() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_node()"); + + NodeBuilder builder(buffer); + + detail::add_basic(builder, args...); + detail::add_user(builder, args...); + detail::add_list(builder, args...); + + return buffer.commit(); + } + + /** + * Create a way using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the way will be added. + * @param args The attributes of the way. + * @returns The position in the buffer where this way was added. + */ + template + inline size_t add_way(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_way() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_way()"); + + WayBuilder builder(buffer); + + detail::add_basic(builder, args...); + detail::add_user(builder, args...); + detail::add_list(builder, args...); + detail::add_list(builder, args...); + + return buffer.commit(); + } + + /** + * Create a relation using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the relation will be added. + * @param args The attributes of the relation. + * @returns The position in the buffer where this relation was added. + */ + template + inline size_t add_relation(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_relation() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_relation()"); + + RelationBuilder builder(buffer); + + detail::add_basic(builder, args...); + detail::add_user(builder, args...); + detail::add_list(builder, args...); + detail::add_list(builder, args...); + + return buffer.commit(); + } + + /** + * Create a changeset using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the changeset will be added. + * @param args The attributes of the changeset. + * @returns The position in the buffer where this changeset was added. + */ + template + inline size_t add_changeset(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_changeset() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_changeset()"); + + ChangesetBuilder builder(buffer); + + detail::add_basic(builder, args...); + detail::add_user(builder, args...); + detail::add_list(builder, args...); + detail::add_list(builder, args...); + + return buffer.commit(); + } + + /** + * Create a area using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the area will be added. + * @param args The attributes of the area. + * @returns The position in the buffer where this area was added. + */ + template + inline size_t add_area(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_area() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_area()"); + + AreaBuilder builder(buffer); + + detail::add_basic(builder, args...); + detail::add_user(builder, args...); + detail::add_list(builder, args...); + + (void)std::initializer_list{ + (detail::ring_handler::set_value(builder, args), 0)... + }; + + return buffer.commit(); + } + + /** + * Create a WayNodeList using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the list will be added. + * @param args The contents of the list. + * @returns The position in the buffer where this list was added. + */ + template + inline size_t add_way_node_list(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_way_node_list() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_way_node_list()"); + + { + WayNodeListBuilder builder(buffer); + (void)std::initializer_list{ + (detail::nodes_handler::set_value(builder, args), 0)... + }; + } + + return buffer.commit(); + } + + /** + * Create a TagList using the given arguments and add it to the given buffer. + * + * @param buffer The buffer to which the list will be added. + * @param args The contents of the list. + * @returns The position in the buffer where this list was added. + */ + template + inline size_t add_tag_list(osmium::memory::Buffer& buffer, const TArgs&... args) { + static_assert(sizeof...(args) > 0, "add_tag_list() must have buffer and at least one additional argument"); + static_assert(detail::are_all_handled_by::value, "Attribute not allowed in add_tag_list()"); + + { + TagListBuilder builder(buffer); + (void)std::initializer_list{ + (detail::tags_handler::set_value(builder, args), 0)... + }; + } + + return buffer.commit(); + } + + } // namespace builder + +} // namespace osmium + +#endif // OSMIUM_BUILDER_ATTR_HPP diff --git a/third_party/libosmium/include/osmium/builder/builder.hpp b/third_party/libosmium/include/osmium/builder/builder.hpp index 63eb4bb2d..869fe44e5 100644 --- a/third_party/libosmium/include/osmium/builder/builder.hpp +++ b/third_party/libosmium/include/osmium/builder/builder.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/builder/builder_helper.hpp b/third_party/libosmium/include/osmium/builder/builder_helper.hpp index eebdf338c..e1b7c52ff 100644 --- a/third_party/libosmium/include/osmium/builder/builder_helper.hpp +++ b/third_party/libosmium/include/osmium/builder/builder_helper.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -41,6 +41,7 @@ DEALINGS IN THE SOFTWARE. #include #include +#include namespace osmium { @@ -50,7 +51,11 @@ namespace osmium { namespace builder { - inline const osmium::WayNodeList& build_way_node_list(osmium::memory::Buffer& buffer, const std::initializer_list& nodes) { + /** + * @deprecated + * Use osmium::builder::add_way_node_list() instead. + */ + OSMIUM_DEPRECATED inline const osmium::WayNodeList& build_way_node_list(osmium::memory::Buffer& buffer, const std::initializer_list& nodes) { size_t pos = buffer.committed(); { osmium::builder::WayNodeListBuilder wnl_builder(buffer); @@ -62,6 +67,10 @@ namespace osmium { return buffer.get(pos); } + /** + * @deprecated + * Use osmium::builder::add_tag_list() instead. + */ inline const osmium::TagList& build_tag_list(osmium::memory::Buffer& buffer, const std::initializer_list>& tags) { size_t pos = buffer.committed(); { @@ -74,6 +83,10 @@ namespace osmium { return buffer.get(pos); } + /** + * @deprecated + * Use osmium::builder::add_tag_list() instead. + */ inline const osmium::TagList& build_tag_list_from_map(osmium::memory::Buffer& buffer, const std::map& tags) { size_t pos = buffer.committed(); { @@ -86,6 +99,10 @@ namespace osmium { return buffer.get(pos); } + /** + * @deprecated + * Use osmium::builder::add_tag_list() instead. + */ inline const osmium::TagList& build_tag_list_from_func(osmium::memory::Buffer& buffer, std::function func) { size_t pos = buffer.committed(); { diff --git a/third_party/libosmium/include/osmium/builder/osm_object_builder.hpp b/third_party/libosmium/include/osmium/builder/osm_object_builder.hpp index 82b4b23ce..d4b54f8fc 100644 --- a/third_party/libosmium/include/osmium/builder/osm_object_builder.hpp +++ b/third_party/libosmium/include/osmium/builder/osm_object_builder.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -34,8 +34,10 @@ DEALINGS IN THE SOFTWARE. */ #include +#include #include #include +#include #include #include #include @@ -49,7 +51,6 @@ DEALINGS IN THE SOFTWARE. #include #include #include -#include namespace osmium { @@ -137,6 +138,15 @@ namespace osmium { * * @param tag Pair of key/value 0-terminated strings. */ + void add_tag(const std::pair& tag) { + add_tag(tag.first, tag.second); + } + void add_tag(const std::pair& tag) { + add_tag(tag.first, tag.second); + } + void add_tag(const std::pair& tag) { + add_tag(tag.first, tag.second); + } void add_tag(const std::pair& tag) { add_tag(tag.first, tag.second); } diff --git a/third_party/libosmium/include/osmium/diff_handler.hpp b/third_party/libosmium/include/osmium/diff_handler.hpp index 06d8a93ed..a5fc34fba 100644 --- a/third_party/libosmium/include/osmium/diff_handler.hpp +++ b/third_party/libosmium/include/osmium/diff_handler.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/diff_iterator.hpp b/third_party/libosmium/include/osmium/diff_iterator.hpp index 6725fecc8..6e0ba4bbf 100644 --- a/third_party/libosmium/include/osmium/diff_iterator.hpp +++ b/third_party/libosmium/include/osmium/diff_iterator.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/diff_visitor.hpp b/third_party/libosmium/include/osmium/diff_visitor.hpp index ac16a8ed4..95660de6b 100644 --- a/third_party/libosmium/include/osmium/diff_visitor.hpp +++ b/third_party/libosmium/include/osmium/diff_visitor.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/dynamic_handler.hpp b/third_party/libosmium/include/osmium/dynamic_handler.hpp index 7077554ff..e7c9900fa 100644 --- a/third_party/libosmium/include/osmium/dynamic_handler.hpp +++ b/third_party/libosmium/include/osmium/dynamic_handler.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/experimental/flex_reader.hpp b/third_party/libosmium/include/osmium/experimental/flex_reader.hpp index c1d235746..8059ea32a 100644 --- a/third_party/libosmium/include/osmium/experimental/flex_reader.hpp +++ b/third_party/libosmium/include/osmium/experimental/flex_reader.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/fwd.hpp b/third_party/libosmium/include/osmium/fwd.hpp index bfcb5f57f..84def8ef1 100644 --- a/third_party/libosmium/include/osmium/fwd.hpp +++ b/third_party/libosmium/include/osmium/fwd.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/coordinates.hpp b/third_party/libosmium/include/osmium/geom/coordinates.hpp index 6544e68aa..0f1387622 100644 --- a/third_party/libosmium/include/osmium/geom/coordinates.hpp +++ b/third_party/libosmium/include/osmium/geom/coordinates.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/factory.hpp b/third_party/libosmium/include/osmium/geom/factory.hpp index 19375806b..394228eb9 100644 --- a/third_party/libosmium/include/osmium/geom/factory.hpp +++ b/third_party/libosmium/include/osmium/geom/factory.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/geojson.hpp b/third_party/libosmium/include/osmium/geom/geojson.hpp index e5b5a9cfc..044a89f86 100644 --- a/third_party/libosmium/include/osmium/geom/geojson.hpp +++ b/third_party/libosmium/include/osmium/geom/geojson.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/geos.hpp b/third_party/libosmium/include/osmium/geom/geos.hpp index 49b1fd7c0..f9026e5a9 100644 --- a/third_party/libosmium/include/osmium/geom/geos.hpp +++ b/third_party/libosmium/include/osmium/geom/geos.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/haversine.hpp b/third_party/libosmium/include/osmium/geom/haversine.hpp index e62a31b03..632bc1612 100644 --- a/third_party/libosmium/include/osmium/geom/haversine.hpp +++ b/third_party/libosmium/include/osmium/geom/haversine.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/mercator_projection.hpp b/third_party/libosmium/include/osmium/geom/mercator_projection.hpp index 22a0d646b..a0c38088a 100644 --- a/third_party/libosmium/include/osmium/geom/mercator_projection.hpp +++ b/third_party/libosmium/include/osmium/geom/mercator_projection.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/ogr.hpp b/third_party/libosmium/include/osmium/geom/ogr.hpp index 4d5995cf7..b8e9ef3ab 100644 --- a/third_party/libosmium/include/osmium/geom/ogr.hpp +++ b/third_party/libosmium/include/osmium/geom/ogr.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/projection.hpp b/third_party/libosmium/include/osmium/geom/projection.hpp index 6419101f8..42d95b27e 100644 --- a/third_party/libosmium/include/osmium/geom/projection.hpp +++ b/third_party/libosmium/include/osmium/geom/projection.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -68,10 +68,6 @@ namespace osmium { std::unique_ptr m_crs; - projPJ get() const { - return m_crs.get(); - } - public: CRS(const std::string& crs) : @@ -85,6 +81,13 @@ namespace osmium { CRS(std::string("+init=epsg:") + std::to_string(epsg)) { } + /** + * Get underlying projPJ handle from proj library. + */ + projPJ get() const { + return m_crs.get(); + } + bool is_latlong() const { return pj_is_latlong(m_crs.get()) != 0; } @@ -93,24 +96,24 @@ namespace osmium { return pj_is_geocent(m_crs.get()) != 0; } - /** - * Transform coordinates from one CRS into another. Wraps the same function - * of the proj library. - * - * Coordinates have to be in radians and are produced in radians. - * - * @throws osmmium::projection_error if the projection fails - */ - friend Coordinates transform(const CRS& src, const CRS& dest, Coordinates c) { - int result = pj_transform(src.get(), dest.get(), 1, 1, &c.x, &c.y, nullptr); - if (result != 0) { - throw osmium::projection_error(std::string("projection failed: ") + pj_strerrno(result)); - } - return c; - } - }; // class CRS + /** + * Transform coordinates from one CRS into another. Wraps the same + * function of the proj library. + * + * Coordinates have to be in radians and are produced in radians. + * + * @throws osmmium::projection_error if the projection fails + */ + inline Coordinates transform(const CRS& src, const CRS& dest, Coordinates c) { + int result = pj_transform(src.get(), dest.get(), 1, 1, &c.x, &c.y, nullptr); + if (result != 0) { + throw osmium::projection_error(std::string("projection failed: ") + pj_strerrno(result)); + } + return c; + } + /** * Functor that does projection from WGS84 (EPSG:4326) to the given * CRS. diff --git a/third_party/libosmium/include/osmium/geom/rapid_geojson.hpp b/third_party/libosmium/include/osmium/geom/rapid_geojson.hpp index 87e479bf1..87e13110f 100644 --- a/third_party/libosmium/include/osmium/geom/rapid_geojson.hpp +++ b/third_party/libosmium/include/osmium/geom/rapid_geojson.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/relations.hpp b/third_party/libosmium/include/osmium/geom/relations.hpp index e9e2aa420..76d452e4e 100644 --- a/third_party/libosmium/include/osmium/geom/relations.hpp +++ b/third_party/libosmium/include/osmium/geom/relations.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/tile.hpp b/third_party/libosmium/include/osmium/geom/tile.hpp index 6ca068262..e35c2ee59 100644 --- a/third_party/libosmium/include/osmium/geom/tile.hpp +++ b/third_party/libosmium/include/osmium/geom/tile.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/util.hpp b/third_party/libosmium/include/osmium/geom/util.hpp index 5e9f8228c..fa9c8bc36 100644 --- a/third_party/libosmium/include/osmium/geom/util.hpp +++ b/third_party/libosmium/include/osmium/geom/util.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/wkb.hpp b/third_party/libosmium/include/osmium/geom/wkb.hpp index 49833e66b..19c12165e 100644 --- a/third_party/libosmium/include/osmium/geom/wkb.hpp +++ b/third_party/libosmium/include/osmium/geom/wkb.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/geom/wkt.hpp b/third_party/libosmium/include/osmium/geom/wkt.hpp index 9cf5371a9..ae73b9604 100644 --- a/third_party/libosmium/include/osmium/geom/wkt.hpp +++ b/third_party/libosmium/include/osmium/geom/wkt.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/handler.hpp b/third_party/libosmium/include/osmium/handler.hpp index 47e997efc..3620d6546 100644 --- a/third_party/libosmium/include/osmium/handler.hpp +++ b/third_party/libosmium/include/osmium/handler.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/handler/chain.hpp b/third_party/libosmium/include/osmium/handler/chain.hpp index 4f3291ca6..e59eb05b9 100644 --- a/third_party/libosmium/include/osmium/handler/chain.hpp +++ b/third_party/libosmium/include/osmium/handler/chain.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/handler/check_order.hpp b/third_party/libosmium/include/osmium/handler/check_order.hpp new file mode 100644 index 000000000..143794bd5 --- /dev/null +++ b/third_party/libosmium/include/osmium/handler/check_order.hpp @@ -0,0 +1,136 @@ +#ifndef OSMIUM_HANDLER_CHECK_ORDER_HPP +#define OSMIUM_HANDLER_CHECK_ORDER_HPP + +/* + +This file is part of Osmium (http://osmcode.org/libosmium). + +Copyright 2013-2016 Jochen Topf and others (see README). + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +*/ + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace osmium { + + /** + * Exception thrown when a method in the CheckOrder class detects + * that the input is out of order. + */ + struct out_of_order_error : public std::runtime_error { + + out_of_order_error(const std::string& what) : + std::runtime_error(what) { + } + + out_of_order_error(const char* what) : + std::runtime_error(what) { + } + + }; // struct out_of_order_error + + namespace handler { + + /** + * Handler that can be used to check that an OSM file is ordered + * correctly. Ordered in this case refers to the usual order in OSM + * files: First nodes in the order of their IDs, then ways in the order + * of their IDs, then relations in the order or their IDs. IDs have to + * be unique for each type. + * + * To use this add a CheckOrder member variable to your handler and + * call the node(), way(), and relation() methods from your node(), + * way(), and relations() handlers, respectively. An out_of_order_error + * exception will be thrown when the input is not in order. + */ + class CheckOrder : public osmium::handler::Handler { + + osmium::object_id_type m_max_node_id = std::numeric_limits::min(); + osmium::object_id_type m_max_way_id = std::numeric_limits::min(); + osmium::object_id_type m_max_relation_id = std::numeric_limits::min(); + + public: + + void node(const osmium::Node& node) { + if (m_max_way_id > 0) { + throw out_of_order_error("Found a node after a way."); + } + if (m_max_relation_id > 0) { + throw out_of_order_error("Found a node after a relation."); + } + + if (m_max_node_id >= node.id()) { + throw out_of_order_error("Node IDs out of order."); + } + m_max_node_id = node.id(); + } + + void way(const osmium::Way& way) { + if (m_max_relation_id > 0) { + throw out_of_order_error("Found a way after a relation."); + } + + if (m_max_way_id >= way.id()) { + throw out_of_order_error("Way IDs out of order."); + } + m_max_way_id = way.id(); + } + + void relation(const osmium::Relation& relation) { + if (m_max_relation_id >= relation.id()) { + throw out_of_order_error("Relation IDs out of order."); + } + m_max_relation_id = relation.id(); + } + + osmium::object_id_type max_node_id() const noexcept { + return m_max_node_id; + } + + osmium::object_id_type max_way_id() const noexcept { + return m_max_way_id; + } + + osmium::object_id_type max_relation_id() const noexcept { + return m_max_relation_id; + } + + }; // class CheckOrder + + } // namespace handler + +} // namespace osmium + +#endif // OSMIUM_HANDLER_CHECK_ORDER_HPP diff --git a/third_party/libosmium/include/osmium/handler/disk_store.hpp b/third_party/libosmium/include/osmium/handler/disk_store.hpp index ccae5962a..b8ab229a3 100644 --- a/third_party/libosmium/include/osmium/handler/disk_store.hpp +++ b/third_party/libosmium/include/osmium/handler/disk_store.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/handler/dump.hpp b/third_party/libosmium/include/osmium/handler/dump.hpp index a23236e10..3863b77ec 100644 --- a/third_party/libosmium/include/osmium/handler/dump.hpp +++ b/third_party/libosmium/include/osmium/handler/dump.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/handler/node_locations_for_ways.hpp b/third_party/libosmium/include/osmium/handler/node_locations_for_ways.hpp index 8d31310c3..f62a4db7c 100644 --- a/third_party/libosmium/include/osmium/handler/node_locations_for_ways.hpp +++ b/third_party/libosmium/include/osmium/handler/node_locations_for_ways.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/handler/object_relations.hpp b/third_party/libosmium/include/osmium/handler/object_relations.hpp index dc4aa45d8..4afcf6a6d 100644 --- a/third_party/libosmium/include/osmium/handler/object_relations.hpp +++ b/third_party/libosmium/include/osmium/handler/object_relations.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/bool_vector.hpp b/third_party/libosmium/include/osmium/index/bool_vector.hpp index 04850a5fc..e6e190e27 100644 --- a/third_party/libosmium/include/osmium/index/bool_vector.hpp +++ b/third_party/libosmium/include/osmium/index/bool_vector.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/create_map_with_fd.hpp b/third_party/libosmium/include/osmium/index/detail/create_map_with_fd.hpp index a2e6b768a..640b3c693 100644 --- a/third_party/libosmium/include/osmium/index/detail/create_map_with_fd.hpp +++ b/third_party/libosmium/include/osmium/index/detail/create_map_with_fd.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/mmap_vector_anon.hpp b/third_party/libosmium/include/osmium/index/detail/mmap_vector_anon.hpp index 12a18036b..cd6942fbf 100644 --- a/third_party/libosmium/include/osmium/index/detail/mmap_vector_anon.hpp +++ b/third_party/libosmium/include/osmium/index/detail/mmap_vector_anon.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/mmap_vector_base.hpp b/third_party/libosmium/include/osmium/index/detail/mmap_vector_base.hpp index e5f28e9b9..aadeef0b5 100644 --- a/third_party/libosmium/include/osmium/index/detail/mmap_vector_base.hpp +++ b/third_party/libosmium/include/osmium/index/detail/mmap_vector_base.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/mmap_vector_file.hpp b/third_party/libosmium/include/osmium/index/detail/mmap_vector_file.hpp index 54ef5137e..666a409d4 100644 --- a/third_party/libosmium/include/osmium/index/detail/mmap_vector_file.hpp +++ b/third_party/libosmium/include/osmium/index/detail/mmap_vector_file.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/tmpfile.hpp b/third_party/libosmium/include/osmium/index/detail/tmpfile.hpp index 06cab6544..0f3d1205b 100644 --- a/third_party/libosmium/include/osmium/index/detail/tmpfile.hpp +++ b/third_party/libosmium/include/osmium/index/detail/tmpfile.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/vector_map.hpp b/third_party/libosmium/include/osmium/index/detail/vector_map.hpp index 2a13061e2..0fa59dd48 100644 --- a/third_party/libosmium/include/osmium/index/detail/vector_map.hpp +++ b/third_party/libosmium/include/osmium/index/detail/vector_map.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/detail/vector_multimap.hpp b/third_party/libosmium/include/osmium/index/detail/vector_multimap.hpp index 789fc9499..35a4cc182 100644 --- a/third_party/libosmium/include/osmium/index/detail/vector_multimap.hpp +++ b/third_party/libosmium/include/osmium/index/detail/vector_multimap.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/index.hpp b/third_party/libosmium/include/osmium/index/index.hpp index 78c142d82..37d022d1b 100644 --- a/third_party/libosmium/include/osmium/index/index.hpp +++ b/third_party/libosmium/include/osmium/index/index.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map.hpp b/third_party/libosmium/include/osmium/index/map.hpp index 68a9c201c..f90a895d1 100644 --- a/third_party/libosmium/include/osmium/index/map.hpp +++ b/third_party/libosmium/include/osmium/index/map.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/all.hpp b/third_party/libosmium/include/osmium/index/map/all.hpp index 9ffadc0de..348d77135 100644 --- a/third_party/libosmium/include/osmium/index/map/all.hpp +++ b/third_party/libosmium/include/osmium/index/map/all.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/dense_file_array.hpp b/third_party/libosmium/include/osmium/index/map/dense_file_array.hpp index d209a875c..6694d11f3 100644 --- a/third_party/libosmium/include/osmium/index/map/dense_file_array.hpp +++ b/third_party/libosmium/include/osmium/index/map/dense_file_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/dense_mem_array.hpp b/third_party/libosmium/include/osmium/index/map/dense_mem_array.hpp index b45eec458..6c33f7dda 100644 --- a/third_party/libosmium/include/osmium/index/map/dense_mem_array.hpp +++ b/third_party/libosmium/include/osmium/index/map/dense_mem_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/dense_mmap_array.hpp b/third_party/libosmium/include/osmium/index/map/dense_mmap_array.hpp index a912aebd1..e63170a77 100644 --- a/third_party/libosmium/include/osmium/index/map/dense_mmap_array.hpp +++ b/third_party/libosmium/include/osmium/index/map/dense_mmap_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/dummy.hpp b/third_party/libosmium/include/osmium/index/map/dummy.hpp index d6a360e56..98d082b82 100644 --- a/third_party/libosmium/include/osmium/index/map/dummy.hpp +++ b/third_party/libosmium/include/osmium/index/map/dummy.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/sparse_file_array.hpp b/third_party/libosmium/include/osmium/index/map/sparse_file_array.hpp index 2ba9315dd..495833c72 100644 --- a/third_party/libosmium/include/osmium/index/map/sparse_file_array.hpp +++ b/third_party/libosmium/include/osmium/index/map/sparse_file_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/sparse_mem_array.hpp b/third_party/libosmium/include/osmium/index/map/sparse_mem_array.hpp index 9adf41f0a..29fadf653 100644 --- a/third_party/libosmium/include/osmium/index/map/sparse_mem_array.hpp +++ b/third_party/libosmium/include/osmium/index/map/sparse_mem_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/sparse_mem_map.hpp b/third_party/libosmium/include/osmium/index/map/sparse_mem_map.hpp index d001b6791..41351c865 100644 --- a/third_party/libosmium/include/osmium/index/map/sparse_mem_map.hpp +++ b/third_party/libosmium/include/osmium/index/map/sparse_mem_map.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/sparse_mem_table.hpp b/third_party/libosmium/include/osmium/index/map/sparse_mem_table.hpp index 797a9265e..241a64f97 100644 --- a/third_party/libosmium/include/osmium/index/map/sparse_mem_table.hpp +++ b/third_party/libosmium/include/osmium/index/map/sparse_mem_table.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/map/sparse_mmap_array.hpp b/third_party/libosmium/include/osmium/index/map/sparse_mmap_array.hpp index c85e2c938..939c389e1 100644 --- a/third_party/libosmium/include/osmium/index/map/sparse_mmap_array.hpp +++ b/third_party/libosmium/include/osmium/index/map/sparse_mmap_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap.hpp b/third_party/libosmium/include/osmium/index/multimap.hpp index a7e1aadb3..de6aa1eb4 100644 --- a/third_party/libosmium/include/osmium/index/multimap.hpp +++ b/third_party/libosmium/include/osmium/index/multimap.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap/all.hpp b/third_party/libosmium/include/osmium/index/multimap/all.hpp index 8b0ae99f9..3fc99d4c9 100644 --- a/third_party/libosmium/include/osmium/index/multimap/all.hpp +++ b/third_party/libosmium/include/osmium/index/multimap/all.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap/hybrid.hpp b/third_party/libosmium/include/osmium/index/multimap/hybrid.hpp index e13ee680f..ba9430232 100644 --- a/third_party/libosmium/include/osmium/index/multimap/hybrid.hpp +++ b/third_party/libosmium/include/osmium/index/multimap/hybrid.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap/sparse_file_array.hpp b/third_party/libosmium/include/osmium/index/multimap/sparse_file_array.hpp index 0b9ae92c5..c36200162 100644 --- a/third_party/libosmium/include/osmium/index/multimap/sparse_file_array.hpp +++ b/third_party/libosmium/include/osmium/index/multimap/sparse_file_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap/sparse_mem_array.hpp b/third_party/libosmium/include/osmium/index/multimap/sparse_mem_array.hpp index c4140cba0..f718edd91 100644 --- a/third_party/libosmium/include/osmium/index/multimap/sparse_mem_array.hpp +++ b/third_party/libosmium/include/osmium/index/multimap/sparse_mem_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap/sparse_mem_multimap.hpp b/third_party/libosmium/include/osmium/index/multimap/sparse_mem_multimap.hpp index 84cb640d9..0859fca21 100644 --- a/third_party/libosmium/include/osmium/index/multimap/sparse_mem_multimap.hpp +++ b/third_party/libosmium/include/osmium/index/multimap/sparse_mem_multimap.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/multimap/sparse_mmap_array.hpp b/third_party/libosmium/include/osmium/index/multimap/sparse_mmap_array.hpp index 9f92555f6..6319c1754 100644 --- a/third_party/libosmium/include/osmium/index/multimap/sparse_mmap_array.hpp +++ b/third_party/libosmium/include/osmium/index/multimap/sparse_mmap_array.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/index/node_locations_map.hpp b/third_party/libosmium/include/osmium/index/node_locations_map.hpp index ca4b1361e..c6ce37dbb 100644 --- a/third_party/libosmium/include/osmium/index/node_locations_map.hpp +++ b/third_party/libosmium/include/osmium/index/node_locations_map.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/any_compression.hpp b/third_party/libosmium/include/osmium/io/any_compression.hpp index 00e8ee2be..7f9f3d562 100644 --- a/third_party/libosmium/include/osmium/io/any_compression.hpp +++ b/third_party/libosmium/include/osmium/io/any_compression.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/any_input.hpp b/third_party/libosmium/include/osmium/io/any_input.hpp index 36f43b785..dd8445132 100644 --- a/third_party/libosmium/include/osmium/io/any_input.hpp +++ b/third_party/libosmium/include/osmium/io/any_input.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/any_output.hpp b/third_party/libosmium/include/osmium/io/any_output.hpp index 990a27bac..53cc5bbd2 100644 --- a/third_party/libosmium/include/osmium/io/any_output.hpp +++ b/third_party/libosmium/include/osmium/io/any_output.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/bzip2_compression.hpp b/third_party/libosmium/include/osmium/io/bzip2_compression.hpp index fc0e33c53..e5cad0be3 100644 --- a/third_party/libosmium/include/osmium/io/bzip2_compression.hpp +++ b/third_party/libosmium/include/osmium/io/bzip2_compression.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/compression.hpp b/third_party/libosmium/include/osmium/io/compression.hpp index b337503ca..7d95661bd 100644 --- a/third_party/libosmium/include/osmium/io/compression.hpp +++ b/third_party/libosmium/include/osmium/io/compression.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/debug_output.hpp b/third_party/libosmium/include/osmium/io/debug_output.hpp index 2836f7987..84db9cdb8 100644 --- a/third_party/libosmium/include/osmium/io/debug_output.hpp +++ b/third_party/libosmium/include/osmium/io/debug_output.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/debug_output_format.hpp b/third_party/libosmium/include/osmium/io/detail/debug_output_format.hpp index f1766dea6..3f7537ea6 100644 --- a/third_party/libosmium/include/osmium/io/detail/debug_output_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/debug_output_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/input_format.hpp b/third_party/libosmium/include/osmium/io/detail/input_format.hpp index d26b1ee92..0d7885131 100644 --- a/third_party/libosmium/include/osmium/io/detail/input_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/input_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/o5m_input_format.hpp b/third_party/libosmium/include/osmium/io/detail/o5m_input_format.hpp index 0318432e8..7293cfa73 100644 --- a/third_party/libosmium/include/osmium/io/detail/o5m_input_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/o5m_input_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/opl_output_format.hpp b/third_party/libosmium/include/osmium/io/detail/opl_output_format.hpp index 2d863ea82..3fedf7e9c 100644 --- a/third_party/libosmium/include/osmium/io/detail/opl_output_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/opl_output_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/output_format.hpp b/third_party/libosmium/include/osmium/io/detail/output_format.hpp index 4c38c4d1e..34ca82f24 100644 --- a/third_party/libosmium/include/osmium/io/detail/output_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/output_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/pbf.hpp b/third_party/libosmium/include/osmium/io/detail/pbf.hpp index 13d552910..88c499326 100644 --- a/third_party/libosmium/include/osmium/io/detail/pbf.hpp +++ b/third_party/libosmium/include/osmium/io/detail/pbf.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/pbf_decoder.hpp b/third_party/libosmium/include/osmium/io/detail/pbf_decoder.hpp index 09e09bf02..43de1c18e 100644 --- a/third_party/libosmium/include/osmium/io/detail/pbf_decoder.hpp +++ b/third_party/libosmium/include/osmium/io/detail/pbf_decoder.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/pbf_input_format.hpp b/third_party/libosmium/include/osmium/io/detail/pbf_input_format.hpp index e9d0e71d1..0c6a9ef54 100644 --- a/third_party/libosmium/include/osmium/io/detail/pbf_input_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/pbf_input_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/pbf_output_format.hpp b/third_party/libosmium/include/osmium/io/detail/pbf_output_format.hpp index 88c1cf489..02b543f69 100644 --- a/third_party/libosmium/include/osmium/io/detail/pbf_output_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/pbf_output_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/protobuf_tags.hpp b/third_party/libosmium/include/osmium/io/detail/protobuf_tags.hpp index 3f2308766..1106f0318 100644 --- a/third_party/libosmium/include/osmium/io/detail/protobuf_tags.hpp +++ b/third_party/libosmium/include/osmium/io/detail/protobuf_tags.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/queue_util.hpp b/third_party/libosmium/include/osmium/io/detail/queue_util.hpp index 6c9f071bc..af8454411 100644 --- a/third_party/libosmium/include/osmium/io/detail/queue_util.hpp +++ b/third_party/libosmium/include/osmium/io/detail/queue_util.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/read_thread.hpp b/third_party/libosmium/include/osmium/io/detail/read_thread.hpp index 6f96c0b65..a933787e3 100644 --- a/third_party/libosmium/include/osmium/io/detail/read_thread.hpp +++ b/third_party/libosmium/include/osmium/io/detail/read_thread.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/read_write.hpp b/third_party/libosmium/include/osmium/io/detail/read_write.hpp index 6db6d8aa8..769e2b39a 100644 --- a/third_party/libosmium/include/osmium/io/detail/read_write.hpp +++ b/third_party/libosmium/include/osmium/io/detail/read_write.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/string_table.hpp b/third_party/libosmium/include/osmium/io/detail/string_table.hpp index 1cb142d00..55c622681 100644 --- a/third_party/libosmium/include/osmium/io/detail/string_table.hpp +++ b/third_party/libosmium/include/osmium/io/detail/string_table.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/string_util.hpp b/third_party/libosmium/include/osmium/io/detail/string_util.hpp index 672266a92..f80088e63 100644 --- a/third_party/libosmium/include/osmium/io/detail/string_util.hpp +++ b/third_party/libosmium/include/osmium/io/detail/string_util.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -110,7 +110,10 @@ namespace osmium { assert(len > 0); if (size_t(len) >= max_size) { - int len2 = string_snprintf(out, +#ifndef NDEBUG + int len2 = +#endif + string_snprintf(out, old_size, size_t(len) + 1, format, diff --git a/third_party/libosmium/include/osmium/io/detail/write_thread.hpp b/third_party/libosmium/include/osmium/io/detail/write_thread.hpp index 81ab1947f..796048638 100644 --- a/third_party/libosmium/include/osmium/io/detail/write_thread.hpp +++ b/third_party/libosmium/include/osmium/io/detail/write_thread.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/xml_input_format.hpp b/third_party/libosmium/include/osmium/io/detail/xml_input_format.hpp index 11d3cba08..8cb5efe8a 100644 --- a/third_party/libosmium/include/osmium/io/detail/xml_input_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/xml_input_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/xml_output_format.hpp b/third_party/libosmium/include/osmium/io/detail/xml_output_format.hpp index 3d7878c8e..09bd6b3ce 100644 --- a/third_party/libosmium/include/osmium/io/detail/xml_output_format.hpp +++ b/third_party/libosmium/include/osmium/io/detail/xml_output_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/detail/zlib.hpp b/third_party/libosmium/include/osmium/io/detail/zlib.hpp index 4d86168d2..2b6dddb94 100644 --- a/third_party/libosmium/include/osmium/io/detail/zlib.hpp +++ b/third_party/libosmium/include/osmium/io/detail/zlib.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/error.hpp b/third_party/libosmium/include/osmium/io/error.hpp index 6b5c677c0..fb6ccf738 100644 --- a/third_party/libosmium/include/osmium/io/error.hpp +++ b/third_party/libosmium/include/osmium/io/error.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/file.hpp b/third_party/libosmium/include/osmium/io/file.hpp index 87fcc3707..56fc8d513 100644 --- a/third_party/libosmium/include/osmium/io/file.hpp +++ b/third_party/libosmium/include/osmium/io/file.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/file_compression.hpp b/third_party/libosmium/include/osmium/io/file_compression.hpp index 292ddcfca..1cfb0f0c2 100644 --- a/third_party/libosmium/include/osmium/io/file_compression.hpp +++ b/third_party/libosmium/include/osmium/io/file_compression.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/file_format.hpp b/third_party/libosmium/include/osmium/io/file_format.hpp index edfb1ff9f..c447cb478 100644 --- a/third_party/libosmium/include/osmium/io/file_format.hpp +++ b/third_party/libosmium/include/osmium/io/file_format.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/gzip_compression.hpp b/third_party/libosmium/include/osmium/io/gzip_compression.hpp index 184787539..e6ca010de 100644 --- a/third_party/libosmium/include/osmium/io/gzip_compression.hpp +++ b/third_party/libosmium/include/osmium/io/gzip_compression.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/header.hpp b/third_party/libosmium/include/osmium/io/header.hpp index 4b0830a62..55ff5c6de 100644 --- a/third_party/libosmium/include/osmium/io/header.hpp +++ b/third_party/libosmium/include/osmium/io/header.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/input_iterator.hpp b/third_party/libosmium/include/osmium/io/input_iterator.hpp index 864776303..8be975930 100644 --- a/third_party/libosmium/include/osmium/io/input_iterator.hpp +++ b/third_party/libosmium/include/osmium/io/input_iterator.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/o5m_input.hpp b/third_party/libosmium/include/osmium/io/o5m_input.hpp index b63f72853..c59e3a6b6 100644 --- a/third_party/libosmium/include/osmium/io/o5m_input.hpp +++ b/third_party/libosmium/include/osmium/io/o5m_input.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/opl_output.hpp b/third_party/libosmium/include/osmium/io/opl_output.hpp index 04385d968..c79e260b6 100644 --- a/third_party/libosmium/include/osmium/io/opl_output.hpp +++ b/third_party/libosmium/include/osmium/io/opl_output.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/output_iterator.hpp b/third_party/libosmium/include/osmium/io/output_iterator.hpp index 1cf1d1dcb..ce050ebab 100644 --- a/third_party/libosmium/include/osmium/io/output_iterator.hpp +++ b/third_party/libosmium/include/osmium/io/output_iterator.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/overwrite.hpp b/third_party/libosmium/include/osmium/io/overwrite.hpp index f9fbc71af..5361698a5 100644 --- a/third_party/libosmium/include/osmium/io/overwrite.hpp +++ b/third_party/libosmium/include/osmium/io/overwrite.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/pbf_input.hpp b/third_party/libosmium/include/osmium/io/pbf_input.hpp index d7f3787ae..ab1f324d7 100644 --- a/third_party/libosmium/include/osmium/io/pbf_input.hpp +++ b/third_party/libosmium/include/osmium/io/pbf_input.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/pbf_output.hpp b/third_party/libosmium/include/osmium/io/pbf_output.hpp index dad1013d7..0a50f2cc9 100644 --- a/third_party/libosmium/include/osmium/io/pbf_output.hpp +++ b/third_party/libosmium/include/osmium/io/pbf_output.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/reader.hpp b/third_party/libosmium/include/osmium/io/reader.hpp index fd2a6d240..7c60511af 100644 --- a/third_party/libosmium/include/osmium/io/reader.hpp +++ b/third_party/libosmium/include/osmium/io/reader.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/reader_iterator.hpp b/third_party/libosmium/include/osmium/io/reader_iterator.hpp index 862078935..116442fd1 100644 --- a/third_party/libosmium/include/osmium/io/reader_iterator.hpp +++ b/third_party/libosmium/include/osmium/io/reader_iterator.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/writer.hpp b/third_party/libosmium/include/osmium/io/writer.hpp index 7cd133d0e..b389698fc 100644 --- a/third_party/libosmium/include/osmium/io/writer.hpp +++ b/third_party/libosmium/include/osmium/io/writer.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/writer_options.hpp b/third_party/libosmium/include/osmium/io/writer_options.hpp index ef1955312..9f6416424 100644 --- a/third_party/libosmium/include/osmium/io/writer_options.hpp +++ b/third_party/libosmium/include/osmium/io/writer_options.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/xml_input.hpp b/third_party/libosmium/include/osmium/io/xml_input.hpp index dfcd0a9fc..87f4ecc81 100644 --- a/third_party/libosmium/include/osmium/io/xml_input.hpp +++ b/third_party/libosmium/include/osmium/io/xml_input.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/io/xml_output.hpp b/third_party/libosmium/include/osmium/io/xml_output.hpp index 18a13869d..344487d5d 100644 --- a/third_party/libosmium/include/osmium/io/xml_output.hpp +++ b/third_party/libosmium/include/osmium/io/xml_output.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/memory/buffer.hpp b/third_party/libosmium/include/osmium/memory/buffer.hpp index bc6e9f8b9..07a31fed9 100644 --- a/third_party/libosmium/include/osmium/memory/buffer.hpp +++ b/third_party/libosmium/include/osmium/memory/buffer.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -39,9 +39,9 @@ DEALINGS IN THE SOFTWARE. #include #include #include +#include #include #include -#include #include #include @@ -108,7 +108,7 @@ namespace osmium { private: - std::vector m_memory; + std::unique_ptr m_memory; unsigned char* m_data; size_t m_capacity; size_t m_written; @@ -195,8 +195,8 @@ namespace osmium { * of the alignment. */ explicit Buffer(size_t capacity, auto_grow auto_grow = auto_grow::yes) : - m_memory(capacity), - m_data(m_memory.data()), + m_memory(new unsigned char[capacity]), + m_data(m_memory.get()), m_capacity(capacity), m_written(0), m_committed(0), @@ -302,18 +302,22 @@ namespace osmium { * memory management. * @throws std::invalid_argument if the size isn't a multiple * of the alignment. + * @throws std::bad_alloc if there isn't enough memory available. */ void grow(size_t size) { assert(m_data); - if (m_memory.empty()) { + if (!m_memory) { throw std::logic_error("Can't grow Buffer if it doesn't use internal memory management."); } if (m_capacity < size) { if (size % align_bytes != 0) { throw std::invalid_argument("buffer capacity needs to be multiple of alignment"); } - m_memory.resize(size); - m_data = m_memory.data(); + std::unique_ptr memory(new unsigned char[size]); + std::copy_n(m_memory.get(), m_capacity, memory.get()); + using std::swap; + swap(m_memory, memory); + m_data = m_memory.get(); m_capacity = size; } } @@ -418,7 +422,7 @@ namespace osmium { } // if there's still not enough space, then try growing the buffer. if (m_written + size > m_capacity) { - if (!m_memory.empty() && (m_auto_grow == auto_grow::yes)) { + if (m_memory && (m_auto_grow == auto_grow::yes)) { // double buffer size until there is enough space size_t new_capacity = m_capacity * 2; while (m_written + size > new_capacity) { @@ -654,16 +658,16 @@ namespace osmium { return m_data != nullptr; } - friend void swap(Buffer& lhs, Buffer& rhs) { + void swap(Buffer& other) { using std::swap; - swap(lhs.m_memory, rhs.m_memory); - swap(lhs.m_data, rhs.m_data); - swap(lhs.m_capacity, rhs.m_capacity); - swap(lhs.m_written, rhs.m_written); - swap(lhs.m_committed, rhs.m_committed); - swap(lhs.m_auto_grow, rhs.m_auto_grow); - swap(lhs.m_full, rhs.m_full); + swap(m_memory, other.m_memory); + swap(m_data, other.m_data); + swap(m_capacity, other.m_capacity); + swap(m_written, other.m_written); + swap(m_committed, other.m_committed); + swap(m_auto_grow, other.m_auto_grow); + swap(m_full, other.m_full); } /** @@ -714,6 +718,10 @@ namespace osmium { }; // class Buffer + inline void swap(Buffer& lhs, Buffer& rhs) { + lhs.swap(rhs); + } + /** * Compare two buffers for equality. * diff --git a/third_party/libosmium/include/osmium/memory/collection.hpp b/third_party/libosmium/include/osmium/memory/collection.hpp index 3878b9a3a..17ace7025 100644 --- a/third_party/libosmium/include/osmium/memory/collection.hpp +++ b/third_party/libosmium/include/osmium/memory/collection.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -95,12 +95,18 @@ namespace osmium { } template - friend std::basic_ostream& operator<<(std::basic_ostream& out, const CollectionIterator& iter) { - return out << static_cast(iter.m_data); + void print(std::basic_ostream& out) const { + out << static_cast(m_data); } }; // class CollectionIterator + template + inline std::basic_ostream& operator<<(std::basic_ostream& out, const CollectionIterator& iter) { + iter.print(out); + return out; + } + template class Collection : public Item { diff --git a/third_party/libosmium/include/osmium/memory/item.hpp b/third_party/libosmium/include/osmium/memory/item.hpp index f95ce8807..fd404ce93 100644 --- a/third_party/libosmium/include/osmium/memory/item.hpp +++ b/third_party/libosmium/include/osmium/memory/item.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/memory/item_iterator.hpp b/third_party/libosmium/include/osmium/memory/item_iterator.hpp index 87af56830..3886c9870 100644 --- a/third_party/libosmium/include/osmium/memory/item_iterator.hpp +++ b/third_party/libosmium/include/osmium/memory/item_iterator.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -209,12 +209,18 @@ namespace osmium { } template - friend std::basic_ostream& operator<<(std::basic_ostream& out, const ItemIterator& iter) { - return out << static_cast(iter.m_data); + void print(std::basic_ostream& out) const { + out << static_cast(m_data); } }; // class ItemIterator + template + inline std::basic_ostream& operator<<(std::basic_ostream& out, const ItemIterator& iter) { + iter.print(out); + return out; + } + } // namespace memory } // namespace osmium diff --git a/third_party/libosmium/include/osmium/object_pointer_collection.hpp b/third_party/libosmium/include/osmium/object_pointer_collection.hpp index 85566b6a4..09a52934e 100644 --- a/third_party/libosmium/include/osmium/object_pointer_collection.hpp +++ b/third_party/libosmium/include/osmium/object_pointer_collection.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm.hpp b/third_party/libosmium/include/osmium/osm.hpp index e92d9b8ef..594db7572 100644 --- a/third_party/libosmium/include/osmium/osm.hpp +++ b/third_party/libosmium/include/osmium/osm.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/area.hpp b/third_party/libosmium/include/osmium/osm/area.hpp index 7fb2a798b..ee232f0bd 100644 --- a/third_party/libosmium/include/osmium/osm/area.hpp +++ b/third_party/libosmium/include/osmium/osm/area.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/box.hpp b/third_party/libosmium/include/osmium/osm/box.hpp index 155f5e902..6fcf48d6c 100644 --- a/third_party/libosmium/include/osmium/osm/box.hpp +++ b/third_party/libosmium/include/osmium/osm/box.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -100,15 +100,15 @@ namespace osmium { /** * Extend this bounding box by the specified location. If the - * location is undefined, the bounding box is unchanged. If - * the box is undefined it will only contain the location after + * location is invalid, the bounding box is unchanged. If the + * box is undefined it will only contain the new location after * this call. * * @param location The location we want to extend the box by. * @returns A reference to this box. */ Box& extend(const Location& location) noexcept { - if (location) { + if (location.valid()) { if (m_bottom_left) { if (location.x() < m_bottom_left.x()) { m_bottom_left.set_x(location.x()); @@ -147,7 +147,7 @@ namespace osmium { * Box is defined, ie. contains defined locations. */ explicit constexpr operator bool() const noexcept { - return static_cast(m_bottom_left); + return bool(m_bottom_left) && bool(m_top_right); } /** @@ -203,6 +203,9 @@ namespace osmium { /** * Calculate size of the box in square degrees. * + * Note that this measure isn't very useful if you want to know the + * real-world size of the bounding box! + * * @throws osmium::invalid_location unless all coordinates are valid. */ double size() const { diff --git a/third_party/libosmium/include/osmium/osm/changeset.hpp b/third_party/libosmium/include/osmium/osm/changeset.hpp index db3f717da..f59db4808 100644 --- a/third_party/libosmium/include/osmium/osm/changeset.hpp +++ b/third_party/libosmium/include/osmium/osm/changeset.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/crc.hpp b/third_party/libosmium/include/osmium/osm/crc.hpp index f5e01e47b..ff39996f5 100644 --- a/third_party/libosmium/include/osmium/osm/crc.hpp +++ b/third_party/libosmium/include/osmium/osm/crc.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/diff_object.hpp b/third_party/libosmium/include/osmium/osm/diff_object.hpp index d9872eaea..609ab7453 100644 --- a/third_party/libosmium/include/osmium/osm/diff_object.hpp +++ b/third_party/libosmium/include/osmium/osm/diff_object.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/entity.hpp b/third_party/libosmium/include/osmium/osm/entity.hpp index c7f70553c..140a559bc 100644 --- a/third_party/libosmium/include/osmium/osm/entity.hpp +++ b/third_party/libosmium/include/osmium/osm/entity.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/entity_bits.hpp b/third_party/libosmium/include/osmium/osm/entity_bits.hpp index 1c1cb8027..50b3e4cb0 100644 --- a/third_party/libosmium/include/osmium/osm/entity_bits.hpp +++ b/third_party/libosmium/include/osmium/osm/entity_bits.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/item_type.hpp b/third_party/libosmium/include/osmium/osm/item_type.hpp index 95826bc98..272b2dd4d 100644 --- a/third_party/libosmium/include/osmium/osm/item_type.hpp +++ b/third_party/libosmium/include/osmium/osm/item_type.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/location.hpp b/third_party/libosmium/include/osmium/osm/location.hpp index f79117e0a..85f4b162a 100644 --- a/third_party/libosmium/include/osmium/osm/location.hpp +++ b/third_party/libosmium/include/osmium/osm/location.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/node.hpp b/third_party/libosmium/include/osmium/osm/node.hpp index 1ff7d1c28..677ffc784 100644 --- a/third_party/libosmium/include/osmium/osm/node.hpp +++ b/third_party/libosmium/include/osmium/osm/node.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/node_ref.hpp b/third_party/libosmium/include/osmium/osm/node_ref.hpp index e1c9c12e1..05b9ca711 100644 --- a/third_party/libosmium/include/osmium/osm/node_ref.hpp +++ b/third_party/libosmium/include/osmium/osm/node_ref.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/node_ref_list.hpp b/third_party/libosmium/include/osmium/osm/node_ref_list.hpp index f990b88c0..84edc0760 100644 --- a/third_party/libosmium/include/osmium/osm/node_ref_list.hpp +++ b/third_party/libosmium/include/osmium/osm/node_ref_list.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/object.hpp b/third_party/libosmium/include/osmium/osm/object.hpp index c0f46adbd..6d1de6f67 100644 --- a/third_party/libosmium/include/osmium/osm/object.hpp +++ b/third_party/libosmium/include/osmium/osm/object.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/object_comparisons.hpp b/third_party/libosmium/include/osmium/osm/object_comparisons.hpp index bdf99e11c..fe3529b4a 100644 --- a/third_party/libosmium/include/osmium/osm/object_comparisons.hpp +++ b/third_party/libosmium/include/osmium/osm/object_comparisons.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/relation.hpp b/third_party/libosmium/include/osmium/osm/relation.hpp index eec51193d..9c4e69cc7 100644 --- a/third_party/libosmium/include/osmium/osm/relation.hpp +++ b/third_party/libosmium/include/osmium/osm/relation.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/segment.hpp b/third_party/libosmium/include/osmium/osm/segment.hpp index fe43102fc..d35f97066 100644 --- a/third_party/libosmium/include/osmium/osm/segment.hpp +++ b/third_party/libosmium/include/osmium/osm/segment.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/tag.hpp b/third_party/libosmium/include/osmium/osm/tag.hpp index 4eba2210e..3f1a29826 100644 --- a/third_party/libosmium/include/osmium/osm/tag.hpp +++ b/third_party/libosmium/include/osmium/osm/tag.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/timestamp.hpp b/third_party/libosmium/include/osmium/osm/timestamp.hpp index 651b43f68..613752e68 100644 --- a/third_party/libosmium/include/osmium/osm/timestamp.hpp +++ b/third_party/libosmium/include/osmium/osm/timestamp.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include @@ -177,8 +178,9 @@ namespace osmium { } /** - * Return UTC Unix time as string in ISO date/time - * ("yyyy-mm-ddThh:mm:ssZ") format. + * Return the timestamp as string in ISO date/time + * ("yyyy-mm-ddThh:mm:ssZ") format. If the timestamp is invalid, an + * empty string will be returned. */ std::string to_iso() const { std::string s; @@ -186,10 +188,15 @@ namespace osmium { if (m_timestamp != 0) { struct tm tm; time_t sse = seconds_since_epoch(); +#ifndef NDEBUG + auto result = +#endif #ifndef _MSC_VER - gmtime_r(&sse, &tm); + gmtime_r(&sse, &tm); + assert(result != nullptr); #else - gmtime_s(&tm, &sse); + gmtime_s(&tm, &sse); + assert(result == 0); #endif s.resize(timestamp_length); diff --git a/third_party/libosmium/include/osmium/osm/types.hpp b/third_party/libosmium/include/osmium/osm/types.hpp index e4250d966..984dd135c 100644 --- a/third_party/libosmium/include/osmium/osm/types.hpp +++ b/third_party/libosmium/include/osmium/osm/types.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/types_from_string.hpp b/third_party/libosmium/include/osmium/osm/types_from_string.hpp index 67ab2c157..aed064898 100644 --- a/third_party/libosmium/include/osmium/osm/types_from_string.hpp +++ b/third_party/libosmium/include/osmium/osm/types_from_string.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/undirected_segment.hpp b/third_party/libosmium/include/osmium/osm/undirected_segment.hpp index 654ef7d9a..c2442ae3c 100644 --- a/third_party/libosmium/include/osmium/osm/undirected_segment.hpp +++ b/third_party/libosmium/include/osmium/osm/undirected_segment.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/osm/way.hpp b/third_party/libosmium/include/osmium/osm/way.hpp index 90cde8c3c..3bc30b0c6 100644 --- a/third_party/libosmium/include/osmium/osm/way.hpp +++ b/third_party/libosmium/include/osmium/osm/way.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/relations/collector.hpp b/third_party/libosmium/include/osmium/relations/collector.hpp index 7d27b3398..af9d63c1a 100644 --- a/third_party/libosmium/include/osmium/relations/collector.hpp +++ b/third_party/libosmium/include/osmium/relations/collector.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/relations/detail/member_meta.hpp b/third_party/libosmium/include/osmium/relations/detail/member_meta.hpp index ea86734ea..a540f4378 100644 --- a/third_party/libosmium/include/osmium/relations/detail/member_meta.hpp +++ b/third_party/libosmium/include/osmium/relations/detail/member_meta.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/relations/detail/relation_meta.hpp b/third_party/libosmium/include/osmium/relations/detail/relation_meta.hpp index a48c50acc..93aa41cf2 100644 --- a/third_party/libosmium/include/osmium/relations/detail/relation_meta.hpp +++ b/third_party/libosmium/include/osmium/relations/detail/relation_meta.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/tags/filter.hpp b/third_party/libosmium/include/osmium/tags/filter.hpp index 0d3fc4ee2..407992e6d 100644 --- a/third_party/libosmium/include/osmium/tags/filter.hpp +++ b/third_party/libosmium/include/osmium/tags/filter.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/tags/regex_filter.hpp b/third_party/libosmium/include/osmium/tags/regex_filter.hpp index 725c42376..8ea6d60c3 100644 --- a/third_party/libosmium/include/osmium/tags/regex_filter.hpp +++ b/third_party/libosmium/include/osmium/tags/regex_filter.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/tags/taglist.hpp b/third_party/libosmium/include/osmium/tags/taglist.hpp index 8fc9c68cd..b1f346fe1 100644 --- a/third_party/libosmium/include/osmium/tags/taglist.hpp +++ b/third_party/libosmium/include/osmium/tags/taglist.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/thread/function_wrapper.hpp b/third_party/libosmium/include/osmium/thread/function_wrapper.hpp index 2fc0b7e22..4366c0a7c 100644 --- a/third_party/libosmium/include/osmium/thread/function_wrapper.hpp +++ b/third_party/libosmium/include/osmium/thread/function_wrapper.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/thread/pool.hpp b/third_party/libosmium/include/osmium/thread/pool.hpp index f7b4f4038..207f55514 100644 --- a/third_party/libosmium/include/osmium/thread/pool.hpp +++ b/third_party/libosmium/include/osmium/thread/pool.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/thread/queue.hpp b/third_party/libosmium/include/osmium/thread/queue.hpp index 65b18475c..771735883 100644 --- a/third_party/libosmium/include/osmium/thread/queue.hpp +++ b/third_party/libosmium/include/osmium/thread/queue.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/thread/sorted_queue.hpp b/third_party/libosmium/include/osmium/thread/sorted_queue.hpp index e76ade101..5478643c9 100644 --- a/third_party/libosmium/include/osmium/thread/sorted_queue.hpp +++ b/third_party/libosmium/include/osmium/thread/sorted_queue.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/thread/util.hpp b/third_party/libosmium/include/osmium/thread/util.hpp index a20e618a0..2ef331a2c 100644 --- a/third_party/libosmium/include/osmium/thread/util.hpp +++ b/third_party/libosmium/include/osmium/thread/util.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/cast.hpp b/third_party/libosmium/include/osmium/util/cast.hpp index 4866fdec4..c31ffce79 100644 --- a/third_party/libosmium/include/osmium/util/cast.hpp +++ b/third_party/libosmium/include/osmium/util/cast.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/compatibility.hpp b/third_party/libosmium/include/osmium/util/compatibility.hpp index 27adca7b7..b83cc1558 100644 --- a/third_party/libosmium/include/osmium/util/compatibility.hpp +++ b/third_party/libosmium/include/osmium/util/compatibility.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/config.hpp b/third_party/libosmium/include/osmium/util/config.hpp index e31cd6a9b..c40512322 100644 --- a/third_party/libosmium/include/osmium/util/config.hpp +++ b/third_party/libosmium/include/osmium/util/config.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/delta.hpp b/third_party/libosmium/include/osmium/util/delta.hpp index 558a1d4f9..34c4eb228 100644 --- a/third_party/libosmium/include/osmium/util/delta.hpp +++ b/third_party/libosmium/include/osmium/util/delta.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/double.hpp b/third_party/libosmium/include/osmium/util/double.hpp index e0701394c..1352c5fb1 100644 --- a/third_party/libosmium/include/osmium/util/double.hpp +++ b/third_party/libosmium/include/osmium/util/double.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/endian.hpp b/third_party/libosmium/include/osmium/util/endian.hpp index a5d91543e..fe23a5517 100644 --- a/third_party/libosmium/include/osmium/util/endian.hpp +++ b/third_party/libosmium/include/osmium/util/endian.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/file.hpp b/third_party/libosmium/include/osmium/util/file.hpp index 39e01af83..86b93ff72 100644 --- a/third_party/libosmium/include/osmium/util/file.hpp +++ b/third_party/libosmium/include/osmium/util/file.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/memory.hpp b/third_party/libosmium/include/osmium/util/memory.hpp new file mode 100644 index 000000000..7ef445b1d --- /dev/null +++ b/third_party/libosmium/include/osmium/util/memory.hpp @@ -0,0 +1,99 @@ +#ifndef OSMIUM_UTIL_MEMORY_HPP +#define OSMIUM_UTIL_MEMORY_HPP + +/* + +This file is part of Osmium (http://osmcode.org/libosmium). + +Copyright 2013-2016 Jochen Topf and others (see README). + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +*/ + +#include +#include +#include + +namespace osmium { + + class MemoryUsage { + + int m_current = 0; + int m_peak = 0; + +#ifdef __linux__ + int parse_number(const std::string& line) { + int f = line.find_first_of("0123456789"); + int l = line.find_last_of("0123456789"); + return std::atoi(line.substr(f, l-f+1).c_str()); + } +#endif + + public: + + /** + * Get the memory usage for the current process. The constructor will + * get the memory usage. Use the current() and peak() calls to access + * the result. + * + * This will only work on Linux, on other architectures this will + * always return 0. + */ + MemoryUsage() { +#ifdef __linux__ + static const char* filename = "/proc/self/status"; + std::ifstream status_file(filename); + + if (status_file.is_open()) { + std::string line; + while (! status_file.eof() ) { + std::getline(status_file, line); + if (line.substr(0, 6) == "VmPeak") { + m_peak = parse_number(line); + } + if (line.substr(0, 6) == "VmSize") { + m_current = parse_number(line); + } + } + } +#endif + } + + /// Return current memory usage in MBytes + int current() const { + return m_current / 1024; + } + + /// Return peak memory usage in MBytes + int peak() const { + return m_peak / 1024; + } + + }; // class MemoryUsage + +} // namespace osmium + +#endif // OSMIUM_UTIL_MEMORY_HPP diff --git a/third_party/libosmium/include/osmium/util/memory_mapping.hpp b/third_party/libosmium/include/osmium/util/memory_mapping.hpp index b187c3c80..67e944e70 100644 --- a/third_party/libosmium/include/osmium/util/memory_mapping.hpp +++ b/third_party/libosmium/include/osmium/util/memory_mapping.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/minmax.hpp b/third_party/libosmium/include/osmium/util/minmax.hpp index 2eb601a24..b4ff4ea90 100644 --- a/third_party/libosmium/include/osmium/util/minmax.hpp +++ b/third_party/libosmium/include/osmium/util/minmax.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/options.hpp b/third_party/libosmium/include/osmium/util/options.hpp index 1019c8bbf..9b00b4811 100644 --- a/third_party/libosmium/include/osmium/util/options.hpp +++ b/third_party/libosmium/include/osmium/util/options.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/string.hpp b/third_party/libosmium/include/osmium/util/string.hpp index 55bfc6cd5..1198288c0 100644 --- a/third_party/libosmium/include/osmium/util/string.hpp +++ b/third_party/libosmium/include/osmium/util/string.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/include/osmium/util/verbose_output.hpp b/third_party/libosmium/include/osmium/util/verbose_output.hpp index 249d67fbf..c7677a436 100644 --- a/third_party/libosmium/include/osmium/util/verbose_output.hpp +++ b/third_party/libosmium/include/osmium/util/verbose_output.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 @@ -115,23 +115,28 @@ namespace osmium { } template - friend VerboseOutput& operator<<(VerboseOutput& verbose_output, const T& value) { - if (verbose_output.m_verbose) { - verbose_output.start_line(); + void print(const T& value) { + if (m_verbose) { + start_line(); std::cerr << value; // check if there was a newline a the end and remember that std::ostringstream output_buffer; output_buffer << value; if (!output_buffer.str().empty() && output_buffer.str().back() == '\n') { - verbose_output.m_newline = true; + m_newline = true; } } - return verbose_output; } }; // class VerboseOutput + template + inline VerboseOutput& operator<<(VerboseOutput& verbose_output, const T& value) { + verbose_output.print(value); + return verbose_output; + } + } // namespace util } // namespace osmium diff --git a/third_party/libosmium/include/osmium/visitor.hpp b/third_party/libosmium/include/osmium/visitor.hpp index c76eb17df..427096864 100644 --- a/third_party/libosmium/include/osmium/visitor.hpp +++ b/third_party/libosmium/include/osmium/visitor.hpp @@ -5,7 +5,7 @@ This file is part of Osmium (http://osmcode.org/libosmium). -Copyright 2013-2015 Jochen Topf and others (see README). +Copyright 2013-2016 Jochen Topf and others (see README). Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/third_party/libosmium/test/CMakeLists.txt b/third_party/libosmium/test/CMakeLists.txt deleted file mode 100644 index f57416120..000000000 --- a/third_party/libosmium/test/CMakeLists.txt +++ /dev/null @@ -1,184 +0,0 @@ -#----------------------------------------------------------------------------- -# -# CMake Config -# -# Libosmium unit tests -# -#----------------------------------------------------------------------------- - -message(STATUS "Configuring unit tests") - -include(CMakeParseArguments) -include_directories(include) - -add_library(testlib STATIC test_main.cpp) - -set(ALL_TESTS "") - -# Otherwise GCC throws a lot of warnings for REQUIRE(...) from Catch v.1.2.1 -if(CMAKE_COMPILER_IS_GNUCXX) - add_definitions(-Wno-parentheses) -endif() - - -#----------------------------------------------------------------------------- -# -# Define function for adding tests -# -# add_unit_tests(group name [ENABLE_IF bool] [LIBS libs] [LABELS labels]) -# -# group - test group (directory) -# name - name of test -# bool - boolean variable telling whether the test should be run (optional) -# libs - lib or libs that should be used when compiling test (optional) -# labels - additional labels this test should get (optional) -# -#----------------------------------------------------------------------------- -function(add_unit_test _tgroup _tname) - set(_testid "${_tgroup}_${_tname}") - set(_tpath "${_tgroup}/${_tname}") - - set(ALL_TESTS "${ALL_TESTS};${_tpath}" PARENT_SCOPE) - - cmake_parse_arguments(_param "" "ENABLE_IF" "LIBS;LABELS" ${ARGN}) - - if(Osmium_DEBUG) - message("${_testid} ENABLE_IF=[${_param_ENABLE_IF}] LIBS=[${_param_LIBS}] LABELS=[${_param_LABELS}]") - endif() - - if((NOT(DEFINED _param_ENABLE_IF)) OR (_param_ENABLE_IF)) - if(Osmium_DEBUG) - message("Adding test: ${_tpath}") - endif() - add_executable(${_testid} t/${_tpath}.cpp) - target_link_libraries(${_testid} testlib) - - if(DEFINED _param_LIBS) - if(Osmium_DEBUG) - message(" Adding libs: ${_param_LIBS}") - endif() - target_link_libraries(${_testid} ${_param_LIBS}) - endif() - - add_test(NAME ${_testid} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${_testid} - ) - - set(_labels "unit;fast;${_tgroup}") - if(DEFINED _param_LABELS) - if(Osmium_DEBUG) - message(" Adding labels: ${_param_LABELS}") - endif() - set(_labels "${_labels};${_param_LABELS}") - endif() - - set_tests_properties(${_testid} PROPERTIES - LABELS "${_labels}" - ENVIRONMENT "OSMIUM_TEST_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}" - ) - else() - message("Skipped test ${_tpath} because a dependency was not found") - set(OSMIUM_SKIPPED_TESTS - "${OSMIUM_SKIPPED_TESTS} ${_tpath}" - CACHE STRING "Tests that were skipped because of missing dependecies") - endif() -endfunction() - -#----------------------------------------------------------------------------- -# -# Add all tests. -# -#----------------------------------------------------------------------------- -add_unit_test(area test_area_id) -add_unit_test(area test_node_ref_segment) - -add_unit_test(basic test_box) -add_unit_test(basic test_changeset) -add_unit_test(basic test_crc) -add_unit_test(basic test_entity_bits) -add_unit_test(basic test_location) -add_unit_test(basic test_node) -add_unit_test(basic test_node_ref) -add_unit_test(basic test_object_comparisons) -add_unit_test(basic test_relation) -add_unit_test(basic test_timestamp) -add_unit_test(basic test_types_from_string) -add_unit_test(basic test_way) - -add_unit_test(buffer test_buffer_basics) -add_unit_test(buffer test_buffer_node) -add_unit_test(buffer test_buffer_purge) - -if(GEOS_FOUND AND PROJ_FOUND) - set(GEOS_AND_PROJ_FOUND TRUE) -else() - set(GEOS_AND_PROJ_FOUND FALSE) -endif() -add_unit_test(geom test_factory_with_projection - ENABLE_IF ${GEOS_AND_PROJ_FOUND} - LIBS ${GEOS_LIBRARY} ${PROJ_LIBRARY}) - -add_unit_test(geom test_exception) -add_unit_test(geom test_geojson) -add_unit_test(geom test_geos ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY}) -add_unit_test(geom test_geos_wkb ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY}) -add_unit_test(geom test_mercator) -add_unit_test(geom test_ogr ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY}) -add_unit_test(geom test_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY}) -add_unit_test(geom test_tile) -add_unit_test(geom test_wkb) -add_unit_test(geom test_wkt) - -add_unit_test(index test_id_to_location ENABLE_IF ${SPARSEHASH_FOUND}) - -add_unit_test(io test_bzip2 ENABLE_IF ${BZIP2_FOUND} LIBS ${BZIP2_LIBRARIES}) -add_unit_test(io test_file_formats) -add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES};${OSMIUM_PBF_LIBRARIES}") -add_unit_test(io test_reader_with_mock_decompression ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES}) -add_unit_test(io test_reader_with_mock_parser ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT}) -add_unit_test(io test_output_utils) -add_unit_test(io test_output_iterator ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT}) -add_unit_test(io test_string_table) -add_unit_test(io test_writer ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES}) -add_unit_test(io test_writer_with_mock_compression ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES}) -add_unit_test(io test_writer_with_mock_encoder ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES}) - -add_unit_test(tags test_filter) -add_unit_test(tags test_operators) -add_unit_test(tags test_tag_list) - -add_unit_test(thread test_pool ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT}) - -add_unit_test(util test_cast_with_assert) -add_unit_test(util test_delta) -add_unit_test(util test_double) -add_unit_test(util test_file) -add_unit_test(util test_memory_mapping) -add_unit_test(util test_minmax) -add_unit_test(util test_options) -add_unit_test(util test_string) - - -#----------------------------------------------------------------------------- -# -# Check that all tests available in test/t/*/test_*.cpp are run. -# -#----------------------------------------------------------------------------- -file(GLOB TESTS_IN_DIR RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/t" t/*/test_*.cpp) - -foreach(file ${TESTS_IN_DIR}) - string(REPLACE ".cpp" "" out1 ${file}) - string(REPLACE "//" "/" tname ${out1}) - list(FIND ALL_TESTS ${tname} found) - if(${found} EQUAL -1) - message(WARNING "Test '${tname}' not found in cmake config. It will not be run!") - endif() -endforeach() - - -#----------------------------------------------------------------------------- -message(STATUS "Configuring unit tests - done") - - -#----------------------------------------------------------------------------- diff --git a/third_party/libosmium/test/README b/third_party/libosmium/test/README deleted file mode 100644 index 8195824b4..000000000 --- a/third_party/libosmium/test/README +++ /dev/null @@ -1,13 +0,0 @@ -Osmium uses Catch (https://github.com/philsquared/Catch/) for its unit tests. - -Only one header file is needed (catch.hpp) which can be downloaded from -http://builds.catch-lib.net/ and put into the include directory. - -Osmium needs a few changes to catch.hpp, they were patched in. To be able to -compare with the original version, it is stored in include/catch_orig.hpp. - -Changes are: -* Disable more warnings in GCC -* CATCH_CONFIG_CPP11_NULLPTR must be set for MSVC -* Problem with test running in loop: https://github.com/philsquared/Catch/issues/271 - diff --git a/third_party/libosmium/test/data-tests/.gitignore b/third_party/libosmium/test/data-tests/.gitignore deleted file mode 100644 index 98df22eda..000000000 --- a/third_party/libosmium/test/data-tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -multipolygon.qgs~ diff --git a/third_party/libosmium/test/data-tests/CMakeLists.txt b/third_party/libosmium/test/data-tests/CMakeLists.txt deleted file mode 100644 index a36c31cfd..000000000 --- a/third_party/libosmium/test/data-tests/CMakeLists.txt +++ /dev/null @@ -1,118 +0,0 @@ -#----------------------------------------------------------------------------- -# -# CMake Config -# -# Libosmium data tests -# -#----------------------------------------------------------------------------- - -message(STATUS "Configuring data tests") - -if(NOT GDAL_FOUND OR NOT EXPAT_FOUND) - message(STATUS "Sorry, building data tests needs GDAL and Expat") - message(STATUS "Configuring data tests - failed") - return() -endif() - -message(STATUS "Looking for osm-testdata") -find_path(OSM_TESTDATA grid/data/all.osm HINT ../../../osm-testdata) -if(OSM_TESTDATA STREQUAL "OSM_TESTDATA-NOTFOUND") - message(STATUS "Looking for osm-testdata - not found (data tests disabled)") - message(STATUS "Configuring data tests - failed") - return() -endif() -message(STATUS "Looking for osm-testdata - found") - - -#----------------------------------------------------------------------------- - -include_directories("include") -include_directories("../include") - - -#----------------------------------------------------------------------------- -# -# testcases -# -#----------------------------------------------------------------------------- -file(GLOB TESTCASE_CPPS testcases/*.cpp) -add_executable(testdata-testcases testdata-testcases.cpp ${TESTCASE_CPPS}) -target_link_libraries(testdata-testcases - ${OSMIUM_XML_LIBRARIES} -) -add_test(NAME testdata-testcases - COMMAND testdata-testcases -) -set_tests_properties(testdata-testcases PROPERTIES - ENVIRONMENT "TESTCASES_DIR=${OSM_TESTDATA}/grid/data" - LABELS "data;fast") - - -#----------------------------------------------------------------------------- -# -# xml -# -#----------------------------------------------------------------------------- -add_executable(testdata-xml testdata-xml.cpp) -target_link_libraries(testdata-xml - ${OSMIUM_XML_LIBRARIES} -) -add_test(NAME testdata-xml - COMMAND testdata-xml -) -set_tests_properties(testdata-xml PROPERTIES - ENVIRONMENT "TESTDIR=${OSM_TESTDATA}/xml/data" - LABELS "data;fast") - - -#----------------------------------------------------------------------------- -# -# overview -# -#----------------------------------------------------------------------------- -add_executable(testdata-overview testdata-overview.cpp) -target_link_libraries(testdata-overview - ${OSMIUM_XML_LIBRARIES} - ${GDAL_LIBRARIES} -) -add_test(NAME testdata-overview - COMMAND testdata-overview ${OSM_TESTDATA}/grid/data/all.osm -) -set_tests_properties(testdata-overview PROPERTIES - LABELS "data;slow") - - -#----------------------------------------------------------------------------- -# -# multipolygon -# -#----------------------------------------------------------------------------- - -find_program(RUBY ruby) -find_package(Gem COMPONENTS json) -find_program(SPATIALITE spatialite) - -if(RUBY AND GEM_json_FOUND AND SPATIALITE) - add_executable(testdata-multipolygon testdata-multipolygon.cpp) - target_link_libraries(testdata-multipolygon - ${OSMIUM_XML_LIBRARIES} - ${GDAL_LIBRARIES} - ) - - add_test(NAME testdata-multipolygon - COMMAND ${CMAKE_COMMAND} - -D OSM_TESTDATA=${OSM_TESTDATA} - -D RUBY=${RUBY} - -P ${CMAKE_CURRENT_SOURCE_DIR}/run-testdata-multipolygon.cmake) - - set_tests_properties(testdata-multipolygon PROPERTIES LABELS "data;slow") -else() - message(WARNING "Disabled testdata-multipolygon test because 'ruby' and/or 'json' ruby gem and/or 'spatialite' was not found") -endif() - - -#----------------------------------------------------------------------------- -message(STATUS "Configuring data tests - done") - - -#----------------------------------------------------------------------------- diff --git a/third_party/libosmium/test/data-tests/README.md b/third_party/libosmium/test/data-tests/README.md deleted file mode 100644 index 5138bf856..000000000 --- a/third_party/libosmium/test/data-tests/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# OSM Testdata - -This directory contains software that can be used with the osm-testdata -repository at https://github.com/osmcode/osm-testdata . To use it, clone -the `osm-testdata` repository in the same directory where you cloned the -`libosmium` repository. - -Tests will be built if the CMake option `BUILD_DATA_TESTS` is set and run as -part of the `ctest` run. - diff --git a/third_party/libosmium/test/data-tests/include/check_basics_handler.hpp b/third_party/libosmium/test/data-tests/include/check_basics_handler.hpp deleted file mode 100644 index 757ab4d3f..000000000 --- a/third_party/libosmium/test/data-tests/include/check_basics_handler.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef CHECK_BASICS_HANDLER_HPP -#define CHECK_BASICS_HANDLER_HPP - -#include -#include - -#include -#include - -/** - * Check some basics of the input data: - * - * 1. Correct number of nodes, ways, and relations - * 2. Correct ID space used by nodes, ways, and relations - * 3. No ID used more than once - */ -class CheckBasicsHandler : public osmium::handler::Handler { - - // Lower bound for the id range allowed in this test. - int m_id_range; - - // In the beginning these contains the number of nodes, ways, and relations - // supposedly in the data.osm file. They will be decremented on each object - // and have to be 0 at the end. - int m_num_nodes; - int m_num_ways; - int m_num_relations; - - // All IDs encountered in the data.osm file will be stored in this set and - // checked for duplicates. - std::unordered_set m_ids; - - // Check id is in range [min, max] and that it isn't more than once in input. - void id_check(osmium::object_id_type id, osmium::object_id_type min, osmium::object_id_type max) { - if (id < m_id_range + min || id > m_id_range + max) { - std::cerr << " id " << id << " out of range for this test case\n"; - exit(1); - } - - auto r = m_ids.insert(id); - if (!r.second) { - std::cerr << " id " << id << " contained twice in data.osm\n"; - exit(1); - } - } - -public: - - static const int ids_per_testcase = 1000; - - CheckBasicsHandler(int testcase, int nodes, int ways, int relations) : - osmium::handler::Handler(), - m_id_range(testcase * ids_per_testcase), - m_num_nodes(nodes), - m_num_ways(ways), - m_num_relations(relations) { - } - - ~CheckBasicsHandler() { - if (m_num_nodes != 0) { - std::cerr << " wrong number of nodes in data.osm\n"; - exit(1); - } - if (m_num_ways != 0) { - std::cerr << " wrong number of ways in data.osm\n"; - exit(1); - } - if (m_num_relations != 0) { - std::cerr << " wrong number of relations in data.osm\n"; - exit(1); - } - } - - void node(const osmium::Node& node) { - id_check(node.id(), 0, 799); - --m_num_nodes; - } - - void way(const osmium::Way& way) { - id_check(way.id(), 800, 899); - --m_num_ways; - } - - void relations(const osmium::Relation& relation) { - id_check(relation.id(), 900, 999); - --m_num_relations; - } - -}; // CheckBasicsHandler - - -#endif // CHECK_BASICS_HANDLER_HPP diff --git a/third_party/libosmium/test/data-tests/include/check_wkt_handler.hpp b/third_party/libosmium/test/data-tests/include/check_wkt_handler.hpp deleted file mode 100644 index fe0199e0a..000000000 --- a/third_party/libosmium/test/data-tests/include/check_wkt_handler.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef CHECK_WKT_HANDLER_HPP -#define CHECK_WKT_HANDLER_HPP - -#include -#include -#include -#include -#include - -#include -#include -#include - -class CheckWKTHandler : public osmium::handler::Handler { - - std::map m_geometries; - osmium::geom::WKTFactory<> m_factory; - - void read_wkt_file(const std::string& filename) { - std::ifstream in(filename, std::ifstream::in); - if (in) { - osmium::object_id_type id; - std::string line; - while (std::getline(in, line)) { - size_t pos = line.find_first_of(' '); - - if (pos == std::string::npos) { - std::cerr << filename << " not formatted correctly\n"; - exit(1); - } - - std::string id_str = line.substr(0, pos); - std::istringstream iss(id_str); - iss >> id; - - if (m_geometries.find(id) != m_geometries.end()) { - std::cerr << filename + " contains id " << id << "twice\n"; - exit(1); - } - - m_geometries[id] = line.substr(pos+1); - } - } - } - -public: - - CheckWKTHandler(const std::string& dirname, int test_id) : - osmium::handler::Handler() { - - std::string filename = dirname + "/" + std::to_string(test_id / 100) + "/" + std::to_string(test_id) + "/"; - read_wkt_file(filename + "nodes.wkt"); - read_wkt_file(filename + "ways.wkt"); - } - - ~CheckWKTHandler() { - if (!m_geometries.empty()) { - for (const auto& geom : m_geometries) { - std::cerr << "geometry id " << geom.first << " not in data.osm.\n"; - } - exit(1); - } - } - - void node(const osmium::Node& node) { - const std::string wkt = m_geometries[node.id()]; - assert(wkt != "" && "Missing geometry for node in nodes.wkt"); - - std::string this_wkt = m_factory.create_point(node.location()); - assert(wkt == this_wkt && "wkt geometries don't match"); - m_geometries.erase(node.id()); - } - - void way(const osmium::Way& way) { - const std::string wkt = m_geometries[way.id()]; - assert(wkt != "" && "Missing geometry for way in ways.wkt"); - - std::string this_wkt = m_factory.create_linestring(way); - assert(wkt == this_wkt && "wkt geometries don't match"); - m_geometries.erase(way.id()); - } - -}; // CheckWKTHandler - - -#endif // CHECK_WKT_HANDLER_HPP diff --git a/third_party/libosmium/test/data-tests/include/common.hpp b/third_party/libosmium/test/data-tests/include/common.hpp deleted file mode 100644 index a6fd3df61..000000000 --- a/third_party/libosmium/test/data-tests/include/common.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef COMMON_HPP -#define COMMON_HPP - -#include -#include - -#include -#include -#include -#include -#include - -typedef osmium::index::map::Dummy index_neg_type; -typedef osmium::index::map::SparseMemArray index_pos_type; -typedef osmium::handler::NodeLocationsForWays location_handler_type; - -#include "check_basics_handler.hpp" -#include "check_wkt_handler.hpp" - -#include "testdata-testcases.hpp" - -#endif // COMMON_HPP diff --git a/third_party/libosmium/test/data-tests/include/testdata-testcases.hpp b/third_party/libosmium/test/data-tests/include/testdata-testcases.hpp deleted file mode 100644 index d7d0c01d7..000000000 --- a/third_party/libosmium/test/data-tests/include/testdata-testcases.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef TESTDATA_TESTCASES_HPP -#define TESTDATA_TESTCASES_HPP - -#include - -#include - -extern std::string dirname; - -#endif // TESTDATA_TESTCASES_HPP diff --git a/third_party/libosmium/test/data-tests/multipolygon.qgs b/third_party/libosmium/test/data-tests/multipolygon.qgs deleted file mode 100644 index 5553670bb..000000000 --- a/third_party/libosmium/test/data-tests/multipolygon.qgs +++ /dev/null @@ -1,880 +0,0 @@ - - - - - - degrees - - 0.77500024999999972 - -0.84791712574962541 - 10.22498975000000065 - 3.94791712574962572 - - 0 - - - +proj=longlat +datum=WGS84 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - - - - - - - - - - - - - - - - - - lerrors20140228172357933 - dbname='./multipolygon.db' table="lerrors" (GEOMETRY) sql= - - - - - - Error Lines - - - +proj=longlat +datum=WGS84 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - spatialite - COALESCE( "OGC_FID", '<NULL>' ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - 0 - 0 - OGC_FID - - - - - - - - - - - - . - - 0 - . - generatedlayout - - - - - - multipolygons20140221151811742 - dbname='./multipolygon.db' table="multipolygons" (GEOMETRY) sql= - - - - - - multipolygons - - - +proj=longlat +datum=WGS84 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - spatialite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - 0 - 0 - OGC_FID - - - - - - - - - . - - 0 - . - generatedlayout - - - - - - perrors20140228163658956 - dbname='./multipolygon.db' table="perrors" (GEOMETRY) sql= - - - - - - Error Points - - - +proj=longlat +datum=WGS84 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - spatialite - COALESCE( "OGC_FID", '<NULL>' ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - 0 - 0 - OGC_FID - - - - - - - - - - - - . - - 0 - . - generatedlayout - - - - - - - - - - - 0.82500024999999999 - -0.35415386986094277 - 8.17498974999999994 - 3.45415386986094308 - - - - - - - false - - mp test - - - - 2 - true - D - - - - true - - false - - NONE - - - - - - - - 0 - 255 - 255 - 255 - 255 - 255 - 255 - - - - - - - - - - - EPSG:4326 - - - - - - true - 255 - - - - - - diff --git a/third_party/libosmium/test/data-tests/run-testdata-multipolygon.cmake b/third_party/libosmium/test/data-tests/run-testdata-multipolygon.cmake deleted file mode 100644 index 0d08f5a52..000000000 --- a/third_party/libosmium/test/data-tests/run-testdata-multipolygon.cmake +++ /dev/null @@ -1,46 +0,0 @@ -#----------------------------------------------------------------------------- -# -# Helper script that runs the 'multipolygon' test. -# -#----------------------------------------------------------------------------- - -# Remove files that might be left over from previous run -file(REMOVE multipolygon.db multipolygon-tests.json) - - -#----------------------------------------------------------------------------- -# -# Create multipolygons from test data. -# -#----------------------------------------------------------------------------- -execute_process( - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/testdata-multipolygon - ${OSM_TESTDATA}/grid/data/all.osm - RESULT_VARIABLE _result - OUTPUT_FILE multipolygon.log - ERROR_FILE multipolygon.log -) - -if(_result) - message(FATAL_ERROR "Error running testdata-multipolygon command") -endif() - - -#----------------------------------------------------------------------------- -# -# Compare created multipolygons with reference data. -# -#----------------------------------------------------------------------------- -execute_process( - COMMAND ${RUBY} ${OSM_TESTDATA}/bin/compare-areas.rb - ${OSM_TESTDATA}/grid/data/tests.json - multipolygon-tests.json - RESULT_VARIABLE _result -) - -if(_result) - message(FATAL_ERROR "Error running compare-areas command") -endif() - - -#----------------------------------------------------------------------------- diff --git a/third_party/libosmium/test/data-tests/testcases/test-100.cpp b/third_party/libosmium/test/data-tests/testcases/test-100.cpp deleted file mode 100644 index feafe771a..000000000 --- a/third_party/libosmium/test/data-tests/testcases/test-100.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include "common.hpp" - -class TestHandler100 : public osmium::handler::Handler { - -public: - - TestHandler100() : - osmium::handler::Handler() { - } - - void node(osmium::Node& node) { - if (node.id() == 100000) { - REQUIRE(node.version() == 1); - REQUIRE(node.timestamp() == osmium::Timestamp("2014-01-01T00:00:00Z")); - REQUIRE(node.uid() == 1); - REQUIRE(!strcmp(node.user(), "test")); - REQUIRE(node.changeset() == 1); - REQUIRE(node.location().lon() == 1.02); - REQUIRE(node.location().lat() == 1.02); - } else { - throw std::runtime_error("Unknown ID"); - } - } - -}; // class TestHandler100 - -TEST_CASE("100") { - - SECTION("test 100") { - osmium::io::Reader reader(dirname + "/1/100/data.osm"); - - CheckBasicsHandler check_basics_handler(100, 1, 0, 0); - CheckWKTHandler check_wkt_handler(dirname, 100); - TestHandler100 test_handler; - - osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler); - } - -} - diff --git a/third_party/libosmium/test/data-tests/testcases/test-101.cpp b/third_party/libosmium/test/data-tests/testcases/test-101.cpp deleted file mode 100644 index de2a5fdb7..000000000 --- a/third_party/libosmium/test/data-tests/testcases/test-101.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -#include "common.hpp" - -class TestHandler101 : public osmium::handler::Handler { - -public: - - TestHandler101() : - osmium::handler::Handler() { - } - - void node(osmium::Node& node) { - if (node.id() == 101000) { - REQUIRE(node.version() == 1); - REQUIRE(node.location().lon() == 1.12); - REQUIRE(node.location().lat() == 1.02); - } else if (node.id() == 101001) { - REQUIRE(node.version() == 1); - REQUIRE(node.location().lon() == 1.12); - REQUIRE(node.location().lat() == 1.03); - } else if (node.id() == 101002) { - } else if (node.id() == 101003) { - } else { - throw std::runtime_error("Unknown ID"); - } - } - -}; // class TestHandler101 - -TEST_CASE("101") { - - SECTION("test 101") { - osmium::io::Reader reader(dirname + "/1/101/data.osm"); - - CheckBasicsHandler check_basics_handler(101, 4, 0, 0); - CheckWKTHandler check_wkt_handler(dirname, 101); - TestHandler101 test_handler; - - osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler); - } - -} - diff --git a/third_party/libosmium/test/data-tests/testcases/test-110.cpp b/third_party/libosmium/test/data-tests/testcases/test-110.cpp deleted file mode 100644 index 16b039b1b..000000000 --- a/third_party/libosmium/test/data-tests/testcases/test-110.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -#include "common.hpp" - -class TestHandler110 : public osmium::handler::Handler { - -public: - - TestHandler110() : - osmium::handler::Handler() { - } - - void node(const osmium::Node& node) { - if (node.id() == 110000) { - REQUIRE(node.location().lon() == 1.02); - REQUIRE(node.location().lat() == 1.12); - } else if (node.id() == 110001) { - REQUIRE(node.location().lon() == 1.07); - REQUIRE(node.location().lat() == 1.13); - } else { - throw std::runtime_error("Unknown ID"); - } - } - - void way(const osmium::Way& way) { - if (way.id() == 110800) { - REQUIRE(way.version() == 1); - REQUIRE(way.nodes().size() == 2); - REQUIRE(!way.is_closed()); - - const char *test_id = way.tags().get_value_by_key("test:id"); - REQUIRE(test_id); - REQUIRE(!strcmp(test_id, "110")); - } else { - throw std::runtime_error("Unknown ID"); - } - } - -}; // class TestHandler110 - -TEST_CASE("110") { - - SECTION("test 110") { - osmium::io::Reader reader(dirname + "/1/110/data.osm"); - - index_pos_type index_pos; - index_neg_type index_neg; - location_handler_type location_handler(index_pos, index_neg); - location_handler.ignore_errors(); - - CheckBasicsHandler check_basics_handler(110, 2, 1, 0); - CheckWKTHandler check_wkt_handler(dirname, 110); - TestHandler110 test_handler; - - osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler); - } - -} - diff --git a/third_party/libosmium/test/data-tests/testdata-multipolygon.cpp b/third_party/libosmium/test/data-tests/testdata-multipolygon.cpp deleted file mode 100644 index cf4fc521a..000000000 --- a/third_party/libosmium/test/data-tests/testdata-multipolygon.cpp +++ /dev/null @@ -1,182 +0,0 @@ - -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef osmium::index::map::SparseMemArray index_type; - -typedef osmium::handler::NodeLocationsForWays location_handler_type; - -struct less_charptr { - - bool operator()(const char* a, const char* b) const { - return std::strcmp(a, b) < 0; - } - -}; // less_charptr - -typedef std::map tagmap_type; - -inline tagmap_type create_map(const osmium::TagList& taglist) { - tagmap_type map; - - for (auto& tag : taglist) { - map[tag.key()] = tag.value(); - } - - return map; -} - -class TestHandler : public osmium::handler::Handler { - - gdalcpp::Layer m_layer_point; - gdalcpp::Layer m_layer_lines; - gdalcpp::Layer m_layer_mpoly; - - osmium::geom::OGRFactory<> m_ogr_factory; - osmium::geom::WKTFactory<> m_wkt_factory; - - std::ofstream m_out; - - bool m_first_out {true}; - -public: - - explicit TestHandler(gdalcpp::Dataset& dataset) : - m_layer_point(dataset, "points", wkbPoint), - m_layer_lines(dataset, "lines", wkbLineString), - m_layer_mpoly(dataset, "multipolygons", wkbMultiPolygon), - m_out("multipolygon-tests.json") { - - m_layer_point.add_field("id", OFTReal, 10); - m_layer_point.add_field("type", OFTString, 30); - - m_layer_lines.add_field("id", OFTReal, 10); - m_layer_lines.add_field("type", OFTString, 30); - - m_layer_mpoly.add_field("id", OFTReal, 10); - m_layer_mpoly.add_field("from_type", OFTString, 1); - } - - ~TestHandler() { - m_out << "\n]\n"; - } - - void node(const osmium::Node& node) { - gdalcpp::Feature feature(m_layer_point, m_ogr_factory.create_point(node)); - feature.set_field("id", static_cast(node.id())); - feature.set_field("type", node.tags().get_value_by_key("type")); - feature.add_to_layer(); - } - - void way(const osmium::Way& way) { - try { - gdalcpp::Feature feature(m_layer_lines, m_ogr_factory.create_linestring(way)); - feature.set_field("id", static_cast(way.id())); - feature.set_field("type", way.tags().get_value_by_key("type")); - feature.add_to_layer(); - } catch (osmium::geometry_error&) { - std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n"; - } - } - - void area(const osmium::Area& area) { - if (m_first_out) { - m_out << "[\n"; - m_first_out = false; - } else { - m_out << ",\n"; - } - m_out << "{\n \"test_id\": " << (area.orig_id() / 1000) << ",\n \"area_id\": " << area.id() << ",\n \"from_id\": " << area.orig_id() << ",\n \"from_type\": \"" << (area.from_way() ? "way" : "relation") << "\",\n \"wkt\": \""; - try { - std::string wkt = m_wkt_factory.create_multipolygon(area); - m_out << wkt << "\",\n \"tags\": {"; - - auto tagmap = create_map(area.tags()); - bool first = true; - for (auto& tag : tagmap) { - if (first) { - first = false; - } else { - m_out << ", "; - } - m_out << '"' << tag.first << "\": \"" << tag.second << '"'; - } - m_out << "}\n}"; - } catch (osmium::geometry_error&) { - m_out << "INVALID\"\n}"; - } - try { - gdalcpp::Feature feature(m_layer_mpoly, m_ogr_factory.create_multipolygon(area)); - feature.set_field("id", static_cast(area.orig_id())); - - std::string from_type; - if (area.from_way()) { - from_type = "w"; - } else { - from_type = "r"; - } - feature.set_field("from_type", from_type.c_str()); - feature.add_to_layer(); - } catch (osmium::geometry_error&) { - std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n"; - } - } - -}; // class TestHandler - -/* ================================================== */ - -int main(int argc, char* argv[]) { - if (argc != 2) { - std::cerr << "Usage: " << argv[0] << " INFILE\n"; - exit(1); - } - - std::string output_format("SQLite"); - std::string input_filename(argv[1]); - std::string output_filename("multipolygon.db"); - - CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE"); - gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, { "SPATIALITE=TRUE" }}; - - osmium::area::ProblemReporterOGR problem_reporter(dataset); - osmium::area::Assembler::config_type assembler_config(&problem_reporter); - assembler_config.enable_debug_output(); - osmium::area::MultipolygonCollector collector(assembler_config); - - std::cerr << "Pass 1...\n"; - osmium::io::Reader reader1(input_filename); - collector.read_relations(reader1); - reader1.close(); - std::cerr << "Pass 1 done\n"; - - index_type index; - location_handler_type location_handler(index); - location_handler.ignore_errors(); - - TestHandler test_handler(dataset); - - std::cerr << "Pass 2...\n"; - osmium::io::Reader reader2(input_filename); - osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) { - osmium::apply(area_buffer, test_handler); - })); - reader2.close(); - std::cerr << "Pass 2 done\n"; -} - diff --git a/third_party/libosmium/test/data-tests/testdata-overview.cpp b/third_party/libosmium/test/data-tests/testdata-overview.cpp deleted file mode 100644 index 43d672dd1..000000000 --- a/third_party/libosmium/test/data-tests/testdata-overview.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* The code in this file is released into the Public Domain. */ - -#include - -#include - -#include - -#include -#include -#include -#include -#include - -typedef osmium::index::map::SparseMemArray index_type; -typedef osmium::handler::NodeLocationsForWays location_handler_type; - -class TestOverviewHandler : public osmium::handler::Handler { - - gdalcpp::Layer m_layer_nodes; - gdalcpp::Layer m_layer_labels; - gdalcpp::Layer m_layer_ways; - - osmium::geom::OGRFactory<> m_factory; - -public: - - explicit TestOverviewHandler(gdalcpp::Dataset& dataset) : - m_layer_nodes(dataset, "nodes", wkbPoint), - m_layer_labels(dataset, "labels", wkbPoint), - m_layer_ways(dataset, "ways", wkbLineString) { - - m_layer_nodes.add_field("id", OFTReal, 10); - - m_layer_labels.add_field("id", OFTReal, 10); - m_layer_labels.add_field("label", OFTString, 30); - - m_layer_ways.add_field("id", OFTReal, 10); - m_layer_ways.add_field("test", OFTInteger, 3); - } - - void node(const osmium::Node& node) { - const char* label = node.tags().get_value_by_key("label"); - if (label) { - gdalcpp::Feature feature(m_layer_labels, m_factory.create_point(node)); - feature.set_field("id", static_cast(node.id())); - feature.set_field("label", label); - feature.add_to_layer(); - } else { - gdalcpp::Feature feature(m_layer_nodes, m_factory.create_point(node)); - feature.set_field("id", static_cast(node.id())); - feature.add_to_layer(); - } - } - - void way(const osmium::Way& way) { - try { - gdalcpp::Feature feature(m_layer_ways, m_factory.create_linestring(way)); - feature.set_field("id", static_cast(way.id())); - - const char* test = way.tags().get_value_by_key("test"); - if (test) { - feature.set_field("test", test); - } - - feature.add_to_layer(); - } catch (osmium::geometry_error&) { - std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n"; - } - } - -}; - -/* ================================================== */ - -int main(int argc, char* argv[]) { - if (argc != 2) { - std::cerr << "Usage: " << argv[0] << " INFILE\n"; - exit(1); - } - - std::string output_format("SQLite"); - std::string input_filename(argv[1]); - std::string output_filename("testdata-overview.db"); - ::unlink(output_filename.c_str()); - - CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE"); - gdalcpp::Dataset dataset(output_format, output_filename, gdalcpp::SRS{}, { "SPATIALITE=TRUE" }); - - osmium::io::Reader reader(input_filename); - - index_type index; - location_handler_type location_handler(index); - location_handler.ignore_errors(); - - TestOverviewHandler handler(dataset); - - osmium::apply(reader, location_handler, handler); - reader.close(); -} - diff --git a/third_party/libosmium/test/data-tests/testdata-testcases.cpp b/third_party/libosmium/test/data-tests/testdata-testcases.cpp deleted file mode 100644 index 0ea7fc859..000000000 --- a/third_party/libosmium/test/data-tests/testdata-testcases.cpp +++ /dev/null @@ -1,25 +0,0 @@ - -#include -#include - -#define CATCH_CONFIG_RUNNER - -#include "testdata-testcases.hpp" - -std::string dirname; - -int main(int argc, char* argv[]) { - const char* testcases_dir = getenv("TESTCASES_DIR"); - if (testcases_dir) { - dirname = testcases_dir; - std::cerr << "Running tests from '" << dirname << "' (from TESTCASES_DIR environment variable)\n"; - } else { - std::cerr << "Please set TESTCASES_DIR environment variable.\n"; - exit(1); - } - - int result = Catch::Session().run(argc, argv); - - return result; -} - diff --git a/third_party/libosmium/test/data-tests/testdata-xml.cpp b/third_party/libosmium/test/data-tests/testdata-xml.cpp deleted file mode 100644 index b5a0e9028..000000000 --- a/third_party/libosmium/test/data-tests/testdata-xml.cpp +++ /dev/null @@ -1,561 +0,0 @@ -/* The code in this file is released into the Public Domain. */ - -#define CATCH_CONFIG_MAIN -#include "catch.hpp" - -#include -#include -#include -#include - -#include -#include -#include -#include - -std::string S_(const char* s) { - return std::string(s); -} - -std::string filename(const char* test_id, const char* suffix = "osm") { - const char* testdir = getenv("TESTDIR"); - if (!testdir) { - std::cerr << "You have to set TESTDIR environment variable before running testdata-xml\n"; - exit(2); - } - - std::string f; - f += testdir; - f += "/"; - f += test_id; - f += "/data."; - f += suffix; - return f; -} - -struct header_buffer_type { - osmium::io::Header header; - osmium::memory::Buffer buffer; -}; - -// ============================================= - -// The following helper functions are used to call different parts of the -// Osmium internals used to read and parse XML files. This way those parts -// can be tested individually. These function can not be used in normal -// operations, because they make certain assumptions, for instance that -// file contents fit into small buffers. - -std::string read_file(const char* test_id) { - int fd = osmium::io::detail::open_for_reading(filename(test_id)); - assert(fd >= 0); - - std::string input(10000, '\0'); - auto n = ::read(fd, reinterpret_cast(const_cast(input.data())), 10000); - assert(n >= 0); - input.resize(static_cast(n)); - - close(fd); - - return input; -} - -std::string read_gz_file(const char* test_id, const char* suffix) { - int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix)); - assert(fd >= 0); - - osmium::io::GzipDecompressor gzip_decompressor(fd); - std::string input = gzip_decompressor.read(); - gzip_decompressor.close(); - - return input; -} - - -header_buffer_type parse_xml(std::string input) { - osmium::io::detail::future_string_queue_type input_queue; - osmium::io::detail::future_buffer_queue_type output_queue; - std::promise header_promise; - std::future header_future = header_promise.get_future(); - - osmium::io::detail::add_to_queue(input_queue, std::move(input)); - osmium::io::detail::add_to_queue(input_queue, std::string{}); - - osmium::io::detail::XMLParser parser(input_queue, output_queue, header_promise, osmium::osm_entity_bits::all); - parser.parse(); - - header_buffer_type result; - result.header = header_future.get(); - std::future future_buffer; - output_queue.wait_and_pop(future_buffer); - result.buffer = future_buffer.get(); - - if (result.buffer) { - std::future future_buffer2; - output_queue.wait_and_pop(future_buffer2); - assert(!future_buffer2.get()); - } - - return result; -} - -header_buffer_type read_xml(const char* test_id) { - std::string input = read_file(test_id); - return parse_xml(input); -} - -// ============================================= - -TEST_CASE("Reading OSM XML 100") { - - SECTION("Direct") { - header_buffer_type r = read_xml("100-correct_but_no_data"); - - REQUIRE(r.header.get("generator") == "testdata"); - REQUIRE(0 == r.buffer.committed()); - REQUIRE(! r.buffer); - } - - SECTION("Using Reader") { - osmium::io::Reader reader(filename("100-correct_but_no_data")); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(0 == buffer.committed()); - REQUIRE(! buffer); - reader.close(); - } - - SECTION("Using Reader asking for header only") { - osmium::io::Reader reader(filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - reader.close(); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 101") { - - SECTION("Direct") { - REQUIRE_THROWS_AS(read_xml("101-missing_version"), osmium::format_version_error); - try { - read_xml("101-missing_version"); - } catch (osmium::format_version_error& e) { - REQUIRE(e.version.empty()); - } - } - - SECTION("Using Reader") { - REQUIRE_THROWS_AS({ - osmium::io::Reader reader(filename("101-missing_version")); - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }, osmium::format_version_error); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 102") { - - SECTION("Direct") { - REQUIRE_THROWS_AS(read_xml("102-wrong_version"), osmium::format_version_error); - try { - read_xml("102-wrong_version"); - } catch (osmium::format_version_error& e) { - REQUIRE(e.version == "0.1"); - } - } - - SECTION("Using Reader") { - REQUIRE_THROWS_AS({ - osmium::io::Reader reader(filename("102-wrong_version")); - - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }, osmium::format_version_error); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 103") { - - SECTION("Direct") { - REQUIRE_THROWS_AS(read_xml("103-old_version"), osmium::format_version_error); - try { - read_xml("103-old_version"); - } catch (osmium::format_version_error& e) { - REQUIRE(e.version == "0.5"); - } - } - - SECTION("Using Reader") { - REQUIRE_THROWS_AS({ - osmium::io::Reader reader(filename("103-old_version")); - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }, osmium::format_version_error); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 104") { - - SECTION("Direct") { - REQUIRE_THROWS_AS(read_xml("104-empty_file"), osmium::xml_error); - try { - read_xml("104-empty_file"); - } catch (osmium::xml_error& e) { - REQUIRE(e.line == 1); - REQUIRE(e.column == 0); - } - } - - SECTION("Using Reader") { - REQUIRE_THROWS_AS({ - osmium::io::Reader reader(filename("104-empty_file")); - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }, osmium::xml_error); - } -} - -// ============================================= - -TEST_CASE("Reading OSM XML 105") { - - SECTION("Direct") { - REQUIRE_THROWS_AS(read_xml("105-incomplete_xml_file"), osmium::xml_error); - } - - SECTION("Using Reader") { - REQUIRE_THROWS_AS({ - osmium::io::Reader reader(filename("105-incomplete_xml_file")); - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }, osmium::xml_error); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 120") { - - SECTION("Direct") { - std::string data = read_gz_file("120-correct_gzip_file_without_data", "osm.gz"); - - REQUIRE(data.size() == 102); - - header_buffer_type r = parse_xml(data); - REQUIRE(r.header.get("generator") == "testdata"); - REQUIRE(0 == r.buffer.committed()); - REQUIRE(! r.buffer); - } - - SECTION("Using Reader") { - osmium::io::Reader reader(filename("120-correct_gzip_file_without_data", "osm.gz")); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(0 == buffer.committed()); - REQUIRE(! buffer); - reader.close(); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 121") { - - SECTION("Direct") { - REQUIRE_THROWS_AS( { - read_gz_file("121-truncated_gzip_file", "osm.gz"); - }, osmium::gzip_error); - } - - SECTION("Using Reader") { - // can throw osmium::gzip_error or osmium::xml_error - REQUIRE_THROWS({ - osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz")); - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 122") { - - SECTION("Direct") { - REQUIRE_THROWS_AS( { - read_xml("122-no_osm_element"); - }, osmium::xml_error); - } - - SECTION("Using Reader") { - REQUIRE_THROWS_AS({ - osmium::io::Reader reader(filename("122-no_osm_element")); - osmium::io::Header header = reader.header(); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - }, osmium::xml_error); - } - -} - -// ============================================= - -TEST_CASE("Reading OSM XML 140") { - - SECTION("Using Reader") { - osmium::io::Reader reader(filename("140-unicode")); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - - int count = 0; - for (auto it = buffer.begin(); it != buffer.end(); ++it) { - ++count; - REQUIRE(it->id() == count); - const osmium::TagList& t = it->tags(); - - const char* uc = t["unicode_char"]; - - auto len = atoi(t["unicode_utf8_length"]); - REQUIRE(len == strlen(uc)); - - REQUIRE(S_(uc) == t["unicode_xml"]); - -// workaround for missing support for u8 string literals on Windows -#if !defined(_MSC_VER) - switch (count) { - case 1: - REQUIRE(S_(uc) == u8"a"); - break; - case 2: - REQUIRE(S_(uc) == u8"\u00e4"); - break; - case 3: - REQUIRE(S_(uc) == u8"\u30dc"); - break; - case 4: - REQUIRE(S_(uc) == u8"\U0001d11e"); - break; - case 5: - REQUIRE(S_(uc) == u8"\U0001f6eb"); - break; - default: - REQUIRE(false); // should not be here - } -#endif - } - REQUIRE(count == 5); - } - -} - - -// ============================================= - -TEST_CASE("Reading OSM XML 141") { - - SECTION("Using Reader") { - osmium::io::Reader reader(filename("141-entities")); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - REQUIRE(buffer.committed() > 0); - REQUIRE(buffer.get(0).type() == osmium::item_type::node); - - const osmium::Node& node = buffer.get(0); - const osmium::TagList& tags = node.tags(); - - REQUIRE(S_(tags["less-than"]) == "<"); - REQUIRE(S_(tags["greater-than"]) == ">"); - REQUIRE(S_(tags["apostrophe"]) == "'"); - REQUIRE(S_(tags["ampersand"]) == "&"); - REQUIRE(S_(tags["quote"]) == "\""); - } - -} - - -// ============================================= - -TEST_CASE("Reading OSM XML 142") { - - SECTION("Using Reader to read nodes") { - osmium::io::Reader reader(filename("142-whitespace")); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - - int count = 0; - for (auto it = buffer.begin(); it != buffer.end(); ++it) { - ++count; - REQUIRE(it->id() == count); - REQUIRE(it->tags().size() == 1); - const osmium::Tag& tag = *(it->tags().begin()); - - switch (count) { - case 1: - REQUIRE(S_(it->user()) == "user name"); - REQUIRE(S_(tag.key()) == "key with space"); - REQUIRE(S_(tag.value()) == "value with space"); - break; - case 2: - REQUIRE(S_(it->user()) == "line\nfeed"); - REQUIRE(S_(tag.key()) == "key with\nlinefeed"); - REQUIRE(S_(tag.value()) == "value with\nlinefeed"); - break; - case 3: - REQUIRE(S_(it->user()) == "carriage\rreturn"); - REQUIRE(S_(tag.key()) == "key with\rcarriage\rreturn"); - REQUIRE(S_(tag.value()) == "value with\rcarriage\rreturn"); - break; - case 4: - REQUIRE(S_(it->user()) == "tab\tulator"); - REQUIRE(S_(tag.key()) == "key with\ttab"); - REQUIRE(S_(tag.value()) == "value with\ttab"); - break; - case 5: - REQUIRE(S_(it->user()) == "unencoded linefeed"); - REQUIRE(S_(tag.key()) == "key with unencoded linefeed"); - REQUIRE(S_(tag.value()) == "value with unencoded linefeed"); - break; - default: - REQUIRE(false); // should not be here - } - } - REQUIRE(count == 5); - } - - SECTION("Using Reader to read relation") { - osmium::io::Reader reader(filename("142-whitespace")); - osmium::memory::Buffer buffer = reader.read(); - reader.close(); - - auto it = buffer.begin(); - REQUIRE(it != buffer.end()); - REQUIRE(it->id() == 21); - const auto& members = it->members(); - REQUIRE(members.size() == 5); - - int count = 0; - for (const auto& member : members) { - ++count; - switch (count) { - case 1: - REQUIRE(S_(member.role()) == "role with whitespace"); - break; - case 2: - REQUIRE(S_(member.role()) == "role with\nlinefeed"); - break; - case 3: - REQUIRE(S_(member.role()) == "role with\rcarriage\rreturn"); - break; - case 4: - REQUIRE(S_(member.role()) == "role with\ttab"); - break; - case 5: - REQUIRE(S_(member.role()) == "role with unencoded linefeed"); - break; - default: - REQUIRE(false); // should not be here - } - } - REQUIRE(count == 5); - } - -} - - -// ============================================= - -TEST_CASE("Reading OSM XML 200") { - - SECTION("Direct") { - header_buffer_type r = read_xml("200-nodes"); - - REQUIRE(r.header.get("generator") == "testdata"); - REQUIRE(r.buffer.committed() > 0); - REQUIRE(r.buffer.get(0).type() == osmium::item_type::node); - REQUIRE(r.buffer.get(0).id() == 36966060); - REQUIRE(std::distance(r.buffer.begin(), r.buffer.end()) == 3); - } - - SECTION("Using Reader") { - osmium::io::Reader reader(filename("200-nodes")); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(buffer.committed() > 0); - REQUIRE(buffer.get(0).type() == osmium::item_type::node); - REQUIRE(buffer.get(0).id() == 36966060); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3); - reader.close(); - } - - SECTION("Using Reader asking for nodes") { - osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::node); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(buffer.committed() > 0); - REQUIRE(buffer.get(0).type() == osmium::item_type::node); - REQUIRE(buffer.get(0).id() == 36966060); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3); - reader.close(); - } - - SECTION("Using Reader asking for header only") { - osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::nothing); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - - REQUIRE_THROWS({ - reader.read(); - }); - - reader.close(); - } - - SECTION("Using Reader asking for ways") { - osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::way); - - osmium::io::Header header = reader.header(); - REQUIRE(header.get("generator") == "testdata"); - - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(0 == buffer.committed()); - REQUIRE(! buffer); - reader.close(); - } - -} - diff --git a/third_party/libosmium/test/include/catch.hpp b/third_party/libosmium/test/include/catch.hpp deleted file mode 100644 index 73abfe8c6..000000000 --- a/third_party/libosmium/test/include/catch.hpp +++ /dev/null @@ -1,9416 +0,0 @@ -/* - * Catch v1.2.1 - * Generated: 2015-06-30 18:23:27.961086 - * ---------------------------------------------------------- - * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED - -#define TWOBLUECUBES_CATCH_HPP_INCLUDED - -#ifdef __clang__ -# pragma clang system_header -#elif defined __GNUC__ -# pragma GCC system_header -#endif - -// #included from: internal/catch_suppress_warnings.h - -#define TWOBLUECUBES_CATCH_SUPPRESS_WARNINGS_H_INCLUDED - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(push) -# pragma warning(disable: 161 1682) -# else // __ICC -# pragma clang diagnostic ignored "-Wglobal-constructors" -# pragma clang diagnostic ignored "-Wvariadic-macros" -# pragma clang diagnostic ignored "-Wc99-extensions" -# pragma clang diagnostic ignored "-Wunused-variable" -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wc++98-compat" -# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" -# pragma clang diagnostic ignored "-Wswitch-enum" -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic ignored "-Wvariadic-macros" -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wpadded" -#endif - -#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) -# define CATCH_IMPL -#endif - -#ifdef CATCH_IMPL -# ifndef CLARA_CONFIG_MAIN -# define CLARA_CONFIG_MAIN_NOT_DEFINED -# define CLARA_CONFIG_MAIN -# endif -#endif - -// #included from: internal/catch_notimplemented_exception.h -#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED - -// #included from: catch_common.h -#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED - -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) - -#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr -#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) - -#include -#include -#include - -// #included from: catch_compiler_capabilities.h -#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED - -// Detect a number of compiler features - mostly C++11/14 conformance - by compiler -// The following features are defined: -// -// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? -// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? -// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods -// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? -// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported - -// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? - -// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? - -// In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. -// Many features, at point of detection, define an _INTERNAL_ macro, so they -// can be combined, en-mass, with the _NO_ forms later. - -// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 - -#ifdef __clang__ - -# if __has_feature(cxx_nullptr) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif - -# if __has_feature(cxx_noexcept) -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# endif - -#endif // __clang__ - -//////////////////////////////////////////////////////////////////////////////// -// Borland -#ifdef __BORLANDC__ - -#endif // __BORLANDC__ - -//////////////////////////////////////////////////////////////////////////////// -// EDG -#ifdef __EDG_VERSION__ - -#endif // __EDG_VERSION__ - -//////////////////////////////////////////////////////////////////////////////// -// Digital Mars -#ifdef __DMC__ - -#endif // __DMC__ - -//////////////////////////////////////////////////////////////////////////////// -// GCC -#ifdef __GNUC__ - -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) ) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -#endif - -#endif // __GNUC__ - -//////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#ifdef _MSC_VER - -#if (_MSC_VER >= 1600) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -#endif - -#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) -#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -#endif - -#endif // _MSC_VER - -// Use variadic macros if the compiler supports them -#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ - ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ - ( defined __GNUC__ && __GNUC__ >= 3 ) || \ - ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) - -#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS - -#endif - -//////////////////////////////////////////////////////////////////////////////// -// C++ language feature support - -// catch all support for C++11 -#if (__cplusplus >= 201103L) - -# define CATCH_CPP11_OR_GREATER - -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# endif - -# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# endif - -#endif // __cplusplus >= 201103L - -// Now set the actual defines based on the above + anything the user has configured -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NULLPTR -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NOEXCEPT -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_GENERATED_METHODS -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_IS_ENUM -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_TUPLE -#endif -#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) -#define CATCH_CONFIG_VARIADIC_MACROS -#endif - -// noexcept support: -#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) -# define CATCH_NOEXCEPT noexcept -# define CATCH_NOEXCEPT_IS(x) noexcept(x) -#else -# define CATCH_NOEXCEPT throw() -# define CATCH_NOEXCEPT_IS(x) -#endif - -namespace Catch { - - class NonCopyable { -#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - NonCopyable( NonCopyable const& ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable& operator = ( NonCopyable const& ) = delete; - NonCopyable& operator = ( NonCopyable && ) = delete; -#else - NonCopyable( NonCopyable const& info ); - NonCopyable& operator = ( NonCopyable const& ); -#endif - - protected: - NonCopyable() {} - virtual ~NonCopyable(); - }; - - class SafeBool { - public: - typedef void (SafeBool::*type)() const; - - static type makeSafe( bool value ) { - return value ? &SafeBool::trueValue : 0; - } - private: - void trueValue() const {} - }; - - template - inline void deleteAll( ContainerT& container ) { - typename ContainerT::const_iterator it = container.begin(); - typename ContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete *it; - } - template - inline void deleteAllValues( AssociativeContainerT& container ) { - typename AssociativeContainerT::const_iterator it = container.begin(); - typename AssociativeContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete it->second; - } - - bool startsWith( std::string const& s, std::string const& prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - std::string trim( std::string const& str ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); - - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); - - std::size_t m_count; - std::string m_label; - }; - - struct SourceLineInfo { - - SourceLineInfo(); - SourceLineInfo( char const* _file, std::size_t _line ); - SourceLineInfo( SourceLineInfo const& other ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - SourceLineInfo( SourceLineInfo && ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo& operator = ( SourceLineInfo && ) = default; -# endif - bool empty() const; - bool operator == ( SourceLineInfo const& other ) const; - bool operator < ( SourceLineInfo const& other ) const; - - std::string file; - std::size_t line; - }; - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - - // This is just here to avoid compiler warnings with macro constants and boolean literals - inline bool isTrue( bool value ){ return value; } - inline bool alwaysTrue() { return true; } - inline bool alwaysFalse() { return false; } - - void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); - - // Use this in variadic streaming macros to allow - // >> +StreamEndStop - // as well as - // >> stuff +StreamEndStop - struct StreamEndStop { - std::string operator+() { - return std::string(); - } - }; - template - T const& operator + ( T const& value, StreamEndStop ) { - return value; - } -} - -#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) -#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); - -#include - -namespace Catch { - - class NotImplementedException : public std::exception - { - public: - NotImplementedException( SourceLineInfo const& lineInfo ); - NotImplementedException( NotImplementedException const& ) {} - - virtual ~NotImplementedException() CATCH_NOEXCEPT {} - - virtual const char* what() const CATCH_NOEXCEPT; - - private: - std::string m_what; - SourceLineInfo m_lineInfo; - }; - -} // end namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) - -// #included from: internal/catch_context.h -#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED - -// #included from: catch_interfaces_generators.h -#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED - -#include - -namespace Catch { - - struct IGeneratorInfo { - virtual ~IGeneratorInfo(); - virtual bool moveNext() = 0; - virtual std::size_t getCurrentIndex() const = 0; - }; - - struct IGeneratorsForTest { - virtual ~IGeneratorsForTest(); - - virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; - virtual bool moveNext() = 0; - }; - - IGeneratorsForTest* createGeneratorsForTest(); - -} // end namespace Catch - -// #included from: catch_ptr.hpp -#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - // An intrusive reference counting smart pointer. - // T must implement addRef() and release() methods - // typically implementing the IShared interface - template - class Ptr { - public: - Ptr() : m_p( NULL ){} - Ptr( T* p ) : m_p( p ){ - if( m_p ) - m_p->addRef(); - } - Ptr( Ptr const& other ) : m_p( other.m_p ){ - if( m_p ) - m_p->addRef(); - } - ~Ptr(){ - if( m_p ) - m_p->release(); - } - void reset() { - if( m_p ) - m_p->release(); - m_p = NULL; - } - Ptr& operator = ( T* p ){ - Ptr temp( p ); - swap( temp ); - return *this; - } - Ptr& operator = ( Ptr const& other ){ - Ptr temp( other ); - swap( temp ); - return *this; - } - void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } - T* get() { return m_p; } - const T* get() const{ return m_p; } - T& operator*() const { return *m_p; } - T* operator->() const { return m_p; } - bool operator !() const { return m_p == NULL; } - operator SafeBool::type() const { return SafeBool::makeSafe( m_p != NULL ); } - - private: - T* m_p; - }; - - struct IShared : NonCopyable { - virtual ~IShared(); - virtual void addRef() const = 0; - virtual void release() const = 0; - }; - - template - struct SharedImpl : T { - - SharedImpl() : m_rc( 0 ){} - - virtual void addRef() const { - ++m_rc; - } - virtual void release() const { - if( --m_rc == 0 ) - delete this; - } - - mutable unsigned int m_rc; - }; - -} // end namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -#include -#include -#include - -namespace Catch { - - class TestCase; - class Stream; - struct IResultCapture; - struct IRunner; - struct IGeneratorsForTest; - struct IConfig; - - struct IContext - { - virtual ~IContext(); - - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; - virtual bool advanceGeneratorsForCurrentTest() = 0; - virtual Ptr getConfig() const = 0; - }; - - struct IMutableContext : IContext - { - virtual ~IMutableContext(); - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( Ptr const& config ) = 0; - }; - - IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); - void cleanUpContext(); - Stream createStream( std::string const& streamName ); - -} - -// #included from: internal/catch_test_registry.hpp -#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED - -// #included from: catch_interfaces_testcase.h -#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED - -#include - -namespace Catch { - - class TestSpec; - - struct ITestCase : IShared { - virtual void invoke () const = 0; - protected: - virtual ~ITestCase(); - }; - - class TestCase; - struct IConfig; - - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector& matchingTestCases, bool negated = false ) const = 0; - - }; -} - -namespace Catch { - -template -class MethodTestCase : public SharedImpl { - -public: - MethodTestCase( void (C::*method)() ) : m_method( method ) {} - - virtual void invoke() const { - C obj; - (obj.*m_method)(); - } - -private: - virtual ~MethodTestCase() {} - - void (C::*m_method)(); -}; - -typedef void(*TestFunction)(); - -struct NameAndDesc { - NameAndDesc( const char* _name = "", const char* _description= "" ) - : name( _name ), description( _description ) - {} - - const char* name; - const char* description; -}; - -struct AutoReg { - - AutoReg( TestFunction function, - SourceLineInfo const& lineInfo, - NameAndDesc const& nameAndDesc ); - - template - AutoReg( void (C::*method)(), - char const* className, - NameAndDesc const& nameAndDesc, - SourceLineInfo const& lineInfo ) { - registerTestCase( new MethodTestCase( method ), - className, - nameAndDesc, - lineInfo ); - } - - void registerTestCase( ITestCase* testCase, - char const* className, - NameAndDesc const& nameAndDesc, - SourceLineInfo const& lineInfo ); - - ~AutoReg(); - -private: - AutoReg( AutoReg const& ); - void operator= ( AutoReg const& ); -}; - -} // end namespace Catch - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TESTCASE( ... ) \ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )(); \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )() - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... )\ - namespace{ \ - struct INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) : ClassName{ \ - void test(); \ - }; \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \ - } \ - void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test() - -#else - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )(); \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )() - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\ - namespace{ \ - struct INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) : ClassName{ \ - void test(); \ - }; \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \ - } \ - void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test() - -#endif - -// #included from: internal/catch_capture.hpp -#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED - -// #included from: catch_result_builder.h -#define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED - -// #included from: catch_result_type.h -#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED - -namespace Catch { - - // ResultWas::OfType enum - struct ResultWas { enum OfType { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, - - FailureBit = 0x10, - - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, - - Exception = 0x100 | FailureBit, - - ThrewException = Exception | 1, - DidntThrowException = Exception | 2, - - FatalErrorCondition = 0x200 | FailureBit - - }; }; - - inline bool isOk( ResultWas::OfType resultType ) { - return ( resultType & ResultWas::FailureBit ) == 0; - } - inline bool isJustInfo( int flags ) { - return flags == ResultWas::Info; - } - - // ResultDisposition::Flags enum - struct ResultDisposition { enum Flags { - Normal = 0x01, - - ContinueOnFailure = 0x02, // Failures fail test, but execution continues - FalseTest = 0x04, // Prefix expression with ! - SuppressFail = 0x08 // Failures are reported but do not fail the test - }; }; - - inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { - return static_cast( static_cast( lhs ) | static_cast( rhs ) ); - } - - inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } - inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } - inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } - -} // end namespace Catch - -// #included from: catch_assertionresult.h -#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED - -#include - -namespace Catch { - - struct AssertionInfo - { - AssertionInfo() {} - AssertionInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - std::string const& _capturedExpression, - ResultDisposition::Flags _resultDisposition ); - - std::string macroName; - SourceLineInfo lineInfo; - std::string capturedExpression; - ResultDisposition::Flags resultDisposition; - }; - - struct AssertionResultData - { - AssertionResultData() : resultType( ResultWas::Unknown ) {} - - std::string reconstructedExpression; - std::string message; - ResultWas::OfType resultType; - }; - - class AssertionResult { - public: - AssertionResult(); - AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); - ~AssertionResult(); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - AssertionResult( AssertionResult const& ) = default; - AssertionResult( AssertionResult && ) = default; - AssertionResult& operator = ( AssertionResult const& ) = default; - AssertionResult& operator = ( AssertionResult && ) = default; -# endif - - bool isOk() const; - bool succeeded() const; - ResultWas::OfType getResultType() const; - bool hasExpression() const; - bool hasMessage() const; - std::string getExpression() const; - std::string getExpressionInMacro() const; - bool hasExpandedExpression() const; - std::string getExpandedExpression() const; - std::string getMessage() const; - SourceLineInfo getSourceInfo() const; - std::string getTestMacroName() const; - - protected: - AssertionInfo m_info; - AssertionResultData m_resultData; - }; - -} // end namespace Catch - -namespace Catch { - - struct TestFailureException{}; - - template class ExpressionLhs; - - struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; - - struct CopyableStream { - CopyableStream() {} - CopyableStream( CopyableStream const& other ) { - oss << other.oss.str(); - } - CopyableStream& operator=( CopyableStream const& other ) { - oss.str(""); - oss << other.oss.str(); - return *this; - } - std::ostringstream oss; - }; - - class ResultBuilder { - public: - ResultBuilder( char const* macroName, - SourceLineInfo const& lineInfo, - char const* capturedExpression, - ResultDisposition::Flags resultDisposition ); - - template - ExpressionLhs operator <= ( T const& operand ); - ExpressionLhs operator <= ( bool value ); - - template - ResultBuilder& operator << ( T const& value ) { - m_stream.oss << value; - return *this; - } - - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); - - ResultBuilder& setResultType( ResultWas::OfType result ); - ResultBuilder& setResultType( bool result ); - ResultBuilder& setLhs( std::string const& lhs ); - ResultBuilder& setRhs( std::string const& rhs ); - ResultBuilder& setOp( std::string const& op ); - - void endExpression(); - - std::string reconstructExpression() const; - AssertionResult build() const; - - void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); - void captureResult( ResultWas::OfType resultType ); - void captureExpression(); - void react(); - bool shouldDebugBreak() const; - bool allowThrows() const; - - private: - AssertionInfo m_assertionInfo; - AssertionResultData m_data; - struct ExprComponents { - ExprComponents() : testFalse( false ) {} - bool testFalse; - std::string lhs, rhs, op; - } m_exprComponents; - CopyableStream m_stream; - - bool m_shouldDebugBreak; - bool m_shouldThrow; - }; - -} // namespace Catch - -// Include after due to circular dependency: -// #included from: catch_expression_lhs.hpp -#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED - -// #included from: catch_evaluate.hpp -#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4389) // '==' : signed/unsigned mismatch -#endif - -#include - -namespace Catch { -namespace Internal { - - enum Operator { - IsEqualTo, - IsNotEqualTo, - IsLessThan, - IsGreaterThan, - IsLessThanOrEqualTo, - IsGreaterThanOrEqualTo - }; - - template struct OperatorTraits { static const char* getName(){ return "*error*"; } }; - template<> struct OperatorTraits { static const char* getName(){ return "=="; } }; - template<> struct OperatorTraits { static const char* getName(){ return "!="; } }; - template<> struct OperatorTraits { static const char* getName(){ return "<"; } }; - template<> struct OperatorTraits { static const char* getName(){ return ">"; } }; - template<> struct OperatorTraits { static const char* getName(){ return "<="; } }; - template<> struct OperatorTraits{ static const char* getName(){ return ">="; } }; - - template - inline T& opCast(T const& t) { return const_cast(t); } - -// nullptr_t support based on pull request #154 from Konstantin Baumann -#ifdef CATCH_CONFIG_CPP11_NULLPTR - inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; } -#endif // CATCH_CONFIG_CPP11_NULLPTR - - // So the compare overloads can be operator agnostic we convey the operator as a template - // enum, which is used to specialise an Evaluator for doing the comparison. - template - class Evaluator{}; - - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs) { - return opCast( lhs ) == opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) != opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) < opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) > opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) >= opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) <= opCast( rhs ); - } - }; - - template - bool applyEvaluator( T1 const& lhs, T2 const& rhs ) { - return Evaluator::evaluate( lhs, rhs ); - } - - // This level of indirection allows us to specialise for integer types - // to avoid signed/ unsigned warnings - - // "base" overload - template - bool compare( T1 const& lhs, T2 const& rhs ) { - return Evaluator::evaluate( lhs, rhs ); - } - - // unsigned X to int - template bool compare( unsigned int lhs, int rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned long lhs, int rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned char lhs, int rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - - // unsigned X to long - template bool compare( unsigned int lhs, long rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned long lhs, long rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned char lhs, long rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - - // int to unsigned X - template bool compare( int lhs, unsigned int rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( int lhs, unsigned long rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( int lhs, unsigned char rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - - // long to unsigned X - template bool compare( long lhs, unsigned int rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long lhs, unsigned long rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long lhs, unsigned char rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - - // pointer to long (when comparing against NULL) - template bool compare( long lhs, T* rhs ) { - return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } - template bool compare( T* lhs, long rhs ) { - return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); - } - - // pointer to int (when comparing against NULL) - template bool compare( int lhs, T* rhs ) { - return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } - template bool compare( T* lhs, int rhs ) { - return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); - } - -#ifdef CATCH_CONFIG_CPP11_NULLPTR - // pointer to nullptr_t (when comparing against nullptr) - template bool compare( std::nullptr_t, T* rhs ) { - return Evaluator::evaluate( NULL, rhs ); - } - template bool compare( T* lhs, std::nullptr_t ) { - return Evaluator::evaluate( lhs, NULL ); - } -#endif // CATCH_CONFIG_CPP11_NULLPTR - -} // end of namespace Internal -} // end of namespace Catch - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// #included from: catch_tostring.h -#define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED - -#include -#include -#include -#include -#include - -#ifdef __OBJC__ -// #included from: catch_objc_arc.hpp -#define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED - -#import - -#ifdef __has_feature -#define CATCH_ARC_ENABLED __has_feature(objc_arc) -#else -#define CATCH_ARC_ENABLED 0 -#endif - -void arcSafeRelease( NSObject* obj ); -id performOptionalSelector( id obj, SEL sel ); - -#if !CATCH_ARC_ENABLED -inline void arcSafeRelease( NSObject* obj ) { - [obj release]; -} -inline id performOptionalSelector( id obj, SEL sel ) { - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; - return nil; -} -#define CATCH_UNSAFE_UNRETAINED -#define CATCH_ARC_STRONG -#else -inline void arcSafeRelease( NSObject* ){} -inline id performOptionalSelector( id obj, SEL sel ) { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" -#endif - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - return nil; -} -#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained -#define CATCH_ARC_STRONG __strong -#endif - -#endif - -#ifdef CATCH_CONFIG_CPP11_TUPLE -#include -#endif - -#ifdef CATCH_CONFIG_CPP11_IS_ENUM -#include -#endif - -namespace Catch { - -// Why we're here. -template -std::string toString( T const& value ); - -// Built in overloads - -std::string toString( std::string const& value ); -std::string toString( std::wstring const& value ); -std::string toString( const char* const value ); -std::string toString( char* const value ); -std::string toString( const wchar_t* const value ); -std::string toString( wchar_t* const value ); -std::string toString( int value ); -std::string toString( unsigned long value ); -std::string toString( unsigned int value ); -std::string toString( const double value ); -std::string toString( const float value ); -std::string toString( bool value ); -std::string toString( char value ); -std::string toString( signed char value ); -std::string toString( unsigned char value ); - -#ifdef CATCH_CONFIG_CPP11_NULLPTR -std::string toString( std::nullptr_t ); -#endif - -#ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ); - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); - std::string toString( NSObject* const& nsObject ); -#endif - -namespace Detail { - - extern std::string unprintableString; - - struct BorgType { - template BorgType( T const& ); - }; - - struct TrueType { char sizer[1]; }; - struct FalseType { char sizer[2]; }; - - TrueType& testStreamable( std::ostream& ); - FalseType testStreamable( FalseType ); - - FalseType operator<<( std::ostream const&, BorgType const& ); - - template - struct IsStreamInsertable { - static std::ostream &s; - static T const&t; - enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) }; - }; - -#if defined(CATCH_CONFIG_CPP11_IS_ENUM) - template::value - > - struct EnumStringMaker - { - static std::string convert( T const& ) { return unprintableString; } - }; - - template - struct EnumStringMaker - { - static std::string convert( T const& v ) - { - return ::Catch::toString( - static_cast::type>(v) - ); - } - }; -#endif - template - struct StringMakerBase { -#if defined(CATCH_CONFIG_CPP11_IS_ENUM) - template - static std::string convert( T const& v ) - { - return EnumStringMaker::convert( v ); - } -#else - template - static std::string convert( T const& ) { return unprintableString; } -#endif - }; - - template<> - struct StringMakerBase { - template - static std::string convert( T const& _value ) { - std::ostringstream oss; - oss << _value; - return oss.str(); - } - }; - - std::string rawMemoryToString( const void *object, std::size_t size ); - - template - inline std::string rawMemoryToString( const T& object ) { - return rawMemoryToString( &object, sizeof(object) ); - } - -} // end namespace Detail - -template -struct StringMaker : - Detail::StringMakerBase::value> {}; - -template -struct StringMaker { - template - static std::string convert( U* p ) { - if( !p ) - return INTERNAL_CATCH_STRINGIFY( NULL ); - else - return Detail::rawMemoryToString( p ); - } -}; - -template -struct StringMaker { - static std::string convert( R C::* p ) { - if( !p ) - return INTERNAL_CATCH_STRINGIFY( NULL ); - else - return Detail::rawMemoryToString( p ); - } -}; - -namespace Detail { - template - std::string rangeToString( InputIterator first, InputIterator last ); -} - -//template -//struct StringMaker > { -// static std::string convert( std::vector const& v ) { -// return Detail::rangeToString( v.begin(), v.end() ); -// } -//}; - -template -std::string toString( std::vector const& v ) { - return Detail::rangeToString( v.begin(), v.end() ); -} - -#ifdef CATCH_CONFIG_CPP11_TUPLE - -// toString for tuples -namespace TupleDetail { - template< - typename Tuple, - std::size_t N = 0, - bool = (N < std::tuple_size::value) - > - struct ElementPrinter { - static void print( const Tuple& tuple, std::ostream& os ) - { - os << ( N ? ", " : " " ) - << Catch::toString(std::get(tuple)); - ElementPrinter::print(tuple,os); - } - }; - - template< - typename Tuple, - std::size_t N - > - struct ElementPrinter { - static void print( const Tuple&, std::ostream& ) {} - }; - -} - -template -struct StringMaker> { - - static std::string convert( const std::tuple& tuple ) - { - std::ostringstream os; - os << '{'; - TupleDetail::ElementPrinter>::print( tuple, os ); - os << " }"; - return os.str(); - } -}; -#endif // CATCH_CONFIG_CPP11_TUPLE - -namespace Detail { - template - std::string makeString( T const& value ) { - return StringMaker::convert( value ); - } -} // end namespace Detail - -/// \brief converts any type to a string -/// -/// The default template forwards on to ostringstream - except when an -/// ostringstream overload does not exist - in which case it attempts to detect -/// that and writes {?}. -/// Overload (not specialise) this template for custom typs that you don't want -/// to provide an ostream overload for. -template -std::string toString( T const& value ) { - return StringMaker::convert( value ); -} - - namespace Detail { - template - std::string rangeToString( InputIterator first, InputIterator last ) { - std::ostringstream oss; - oss << "{ "; - if( first != last ) { - oss << Catch::toString( *first ); - for( ++first ; first != last ; ++first ) - oss << ", " << Catch::toString( *first ); - } - oss << " }"; - return oss.str(); - } -} - -} // end namespace Catch - -namespace Catch { - -// Wraps the LHS of an expression and captures the operator and RHS (if any) - -// wrapping them all in a ResultBuilder object -template -class ExpressionLhs { - ExpressionLhs& operator = ( ExpressionLhs const& ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - ExpressionLhs& operator = ( ExpressionLhs && ) = delete; -# endif - -public: - ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - ExpressionLhs( ExpressionLhs const& ) = default; - ExpressionLhs( ExpressionLhs && ) = default; -# endif - - template - ResultBuilder& operator == ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator != ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator < ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator > ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator <= ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator >= ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - ResultBuilder& operator == ( bool rhs ) { - return captureExpression( rhs ); - } - - ResultBuilder& operator != ( bool rhs ) { - return captureExpression( rhs ); - } - - void endExpression() { - bool value = m_lhs ? true : false; - m_rb - .setLhs( Catch::toString( value ) ) - .setResultType( value ) - .endExpression(); - } - - // Only simple binary expressions are allowed on the LHS. - // If more complex compositions are required then place the sub expression in parentheses - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); - -private: - template - ResultBuilder& captureExpression( RhsT const& rhs ) { - return m_rb - .setResultType( Internal::compare( m_lhs, rhs ) ) - .setLhs( Catch::toString( m_lhs ) ) - .setRhs( Catch::toString( rhs ) ) - .setOp( Internal::OperatorTraits::getName() ); - } - -private: - ResultBuilder& m_rb; - T m_lhs; -}; - -} // end namespace Catch - - -namespace Catch { - - template - inline ExpressionLhs ResultBuilder::operator <= ( T const& operand ) { - return ExpressionLhs( *this, operand ); - } - - inline ExpressionLhs ResultBuilder::operator <= ( bool value ) { - return ExpressionLhs( *this, value ); - } - -} // namespace Catch - -// #included from: catch_message.h -#define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED - -#include - -namespace Catch { - - struct MessageInfo { - MessageInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ); - - std::string macroName; - SourceLineInfo lineInfo; - ResultWas::OfType type; - std::string message; - unsigned int sequence; - - bool operator == ( MessageInfo const& other ) const { - return sequence == other.sequence; - } - bool operator < ( MessageInfo const& other ) const { - return sequence < other.sequence; - } - private: - static unsigned int globalCount; - }; - - struct MessageBuilder { - MessageBuilder( std::string const& macroName, - SourceLineInfo const& lineInfo, - ResultWas::OfType type ) - : m_info( macroName, lineInfo, type ) - {} - - template - MessageBuilder& operator << ( T const& value ) { - m_stream << value; - return *this; - } - - MessageInfo m_info; - std::ostringstream m_stream; - }; - - class ScopedMessage { - public: - ScopedMessage( MessageBuilder const& builder ); - ScopedMessage( ScopedMessage const& other ); - ~ScopedMessage(); - - MessageInfo m_info; - }; - -} // end namespace Catch - -// #included from: catch_interfaces_capture.h -#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED - -#include - -namespace Catch { - - class TestCase; - class AssertionResult; - struct AssertionInfo; - struct SectionInfo; - struct MessageInfo; - class ScopedMessageBuilder; - struct Counts; - - struct IResultCapture { - - virtual ~IResultCapture(); - - virtual void assertionEnded( AssertionResult const& result ) = 0; - virtual bool sectionStarted( SectionInfo const& sectionInfo, - Counts& assertions ) = 0; - virtual void sectionEnded( SectionInfo const& name, Counts const& assertions, double _durationInSeconds ) = 0; - virtual void pushScopedMessage( MessageInfo const& message ) = 0; - virtual void popScopedMessage( MessageInfo const& message ) = 0; - - virtual std::string getCurrentTestName() const = 0; - virtual const AssertionResult* getLastResult() const = 0; - - virtual void handleFatalErrorCondition( std::string const& message ) = 0; - }; - - IResultCapture& getResultCapture(); -} - -// #included from: catch_debugger.h -#define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED - -// #included from: catch_platform.h -#define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED - -#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_MAC -#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_IPHONE -#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) -#define CATCH_PLATFORM_WINDOWS -#endif - -#include - -namespace Catch{ - - bool isDebuggerActive(); - void writeToDebugConsole( std::string const& text ); -} - -#ifdef CATCH_PLATFORM_MAC - - // The following code snippet based on: - // http://cocoawithlove.com/2008/03/break-into-debugger.html - #ifdef DEBUG - #if defined(__ppc64__) || defined(__ppc__) - #define CATCH_BREAK_INTO_DEBUGGER() \ - if( Catch::isDebuggerActive() ) { \ - __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ - : : : "memory","r0","r3","r4" ); \ - } - #else - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );} - #endif - #endif - -#elif defined(_MSC_VER) - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { __debugbreak(); } -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) void __stdcall DebugBreak(); - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { DebugBreak(); } -#endif - -#ifndef CATCH_BREAK_INTO_DEBUGGER -#define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); -#endif - -// #included from: catch_interfaces_runner.h -#define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED - -namespace Catch { - class TestCase; - - struct IRunner { - virtual ~IRunner(); - virtual bool aborting() const = 0; - }; -} - -/////////////////////////////////////////////////////////////////////////////// -// In the event of a failure works out if the debugger needs to be invoked -// and/or an exception thrown and takes appropriate action. -// This needs to be done as a macro so the debugger will stop in the user -// source code rather than in Catch library code -#define INTERNAL_CATCH_REACT( resultBuilder ) \ - if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \ - resultBuilder.react(); - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - try { \ - ( __catchResult <= expr ).endExpression(); \ - } \ - catch( ... ) { \ - __catchResult.useActiveException( Catch::ResultDisposition::Normal ); \ - } \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::isTrue( false && (expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \ - INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ - if( Catch::getResultCapture().getLastResult()->succeeded() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \ - INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ - if( !Catch::getResultCapture().getLastResult()->succeeded() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - try { \ - expr; \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - } \ - catch( ... ) { \ - __catchResult.useActiveException( resultDisposition ); \ - } \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS( expr, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - if( __catchResult.allowThrows() ) \ - try { \ - expr; \ - __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ - } \ - catch( ... ) { \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - } \ - else \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - if( __catchResult.allowThrows() ) \ - try { \ - expr; \ - __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ - } \ - catch( exceptionType ) { \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - } \ - catch( ... ) { \ - __catchResult.useActiveException( resultDisposition ); \ - } \ - else \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -/////////////////////////////////////////////////////////////////////////////// -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \ - __catchResult.captureResult( messageType ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) -#else - #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - __catchResult << log + ::Catch::StreamEndStop(); \ - __catchResult.captureResult( messageType ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) -#endif - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_INFO( log, macroName ) \ - Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log; - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg " " #matcher, resultDisposition ); \ - try { \ - std::string matcherAsString = ::Catch::Matchers::matcher.toString(); \ - __catchResult \ - .setLhs( Catch::toString( arg ) ) \ - .setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \ - .setOp( "matches" ) \ - .setResultType( ::Catch::Matchers::matcher.match( arg ) ); \ - __catchResult.captureExpression(); \ - } catch( ... ) { \ - __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \ - } \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -// #included from: internal/catch_section.h -#define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED - -// #included from: catch_section_info.h -#define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED - -namespace Catch { - - struct SectionInfo { - SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description = std::string() ); - - std::string name; - std::string description; - SourceLineInfo lineInfo; - }; - -} // end namespace Catch - -// #included from: catch_totals.hpp -#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED - -#include - -namespace Catch { - - struct Counts { - Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {} - - Counts operator - ( Counts const& other ) const { - Counts diff; - diff.passed = passed - other.passed; - diff.failed = failed - other.failed; - diff.failedButOk = failedButOk - other.failedButOk; - return diff; - } - Counts& operator += ( Counts const& other ) { - passed += other.passed; - failed += other.failed; - failedButOk += other.failedButOk; - return *this; - } - - std::size_t total() const { - return passed + failed + failedButOk; - } - bool allPassed() const { - return failed == 0 && failedButOk == 0; - } - bool allOk() const { - return failed == 0; - } - - std::size_t passed; - std::size_t failed; - std::size_t failedButOk; - }; - - struct Totals { - - Totals operator - ( Totals const& other ) const { - Totals diff; - diff.assertions = assertions - other.assertions; - diff.testCases = testCases - other.testCases; - return diff; - } - - Totals delta( Totals const& prevTotals ) const { - Totals diff = *this - prevTotals; - if( diff.assertions.failed > 0 ) - ++diff.testCases.failed; - else if( diff.assertions.failedButOk > 0 ) - ++diff.testCases.failedButOk; - else - ++diff.testCases.passed; - return diff; - } - - Totals& operator += ( Totals const& other ) { - assertions += other.assertions; - testCases += other.testCases; - return *this; - } - - Counts assertions; - Counts testCases; - }; -} - -// #included from: catch_timer.h -#define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED - -#ifdef CATCH_PLATFORM_WINDOWS -typedef unsigned long long uint64_t; -#else -#include -#endif - -namespace Catch { - - class Timer { - public: - Timer() : m_ticks( 0 ) {} - void start(); - unsigned int getElapsedMicroseconds() const; - unsigned int getElapsedMilliseconds() const; - double getElapsedSeconds() const; - - private: - uint64_t m_ticks; - }; - -} // namespace Catch - -#include - -namespace Catch { - - class Section : NonCopyable { - public: - Section( SectionInfo const& info ); - ~Section(); - - // This indicates whether the section should be executed or not - operator bool() const; - - private: - SectionInfo m_info; - - std::string m_name; - Counts m_assertions; - bool m_sectionIncluded; - Timer m_timer; - }; - -} // end namespace Catch - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define INTERNAL_CATCH_SECTION( ... ) \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) -#else - #define INTERNAL_CATCH_SECTION( name, desc ) \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) ) -#endif - -// #included from: internal/catch_generators.hpp -#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED - -#include -#include -#include -#include - -namespace Catch { - -template -struct IGenerator { - virtual ~IGenerator() {} - virtual T getValue( std::size_t index ) const = 0; - virtual std::size_t size () const = 0; -}; - -template -class BetweenGenerator : public IGenerator { -public: - BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} - - virtual T getValue( std::size_t index ) const { - return m_from+static_cast( index ); - } - - virtual std::size_t size() const { - return static_cast( 1+m_to-m_from ); - } - -private: - - T m_from; - T m_to; -}; - -template -class ValuesGenerator : public IGenerator { -public: - ValuesGenerator(){} - - void add( T value ) { - m_values.push_back( value ); - } - - virtual T getValue( std::size_t index ) const { - return m_values[index]; - } - - virtual std::size_t size() const { - return m_values.size(); - } - -private: - std::vector m_values; -}; - -template -class CompositeGenerator { -public: - CompositeGenerator() : m_totalSize( 0 ) {} - - // *** Move semantics, similar to auto_ptr *** - CompositeGenerator( CompositeGenerator& other ) - : m_fileInfo( other.m_fileInfo ), - m_totalSize( 0 ) - { - move( other ); - } - - CompositeGenerator& setFileInfo( const char* fileInfo ) { - m_fileInfo = fileInfo; - return *this; - } - - ~CompositeGenerator() { - deleteAll( m_composed ); - } - - operator T () const { - size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); - - typename std::vector*>::const_iterator it = m_composed.begin(); - typename std::vector*>::const_iterator itEnd = m_composed.end(); - for( size_t index = 0; it != itEnd; ++it ) - { - const IGenerator* generator = *it; - if( overallIndex >= index && overallIndex < index + generator->size() ) - { - return generator->getValue( overallIndex-index ); - } - index += generator->size(); - } - CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); - return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so - } - - void add( const IGenerator* generator ) { - m_totalSize += generator->size(); - m_composed.push_back( generator ); - } - - CompositeGenerator& then( CompositeGenerator& other ) { - move( other ); - return *this; - } - - CompositeGenerator& then( T value ) { - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( value ); - add( valuesGen ); - return *this; - } - -private: - - void move( CompositeGenerator& other ) { - std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) ); - m_totalSize += other.m_totalSize; - other.m_composed.clear(); - } - - std::vector*> m_composed; - std::string m_fileInfo; - size_t m_totalSize; -}; - -namespace Generators -{ - template - CompositeGenerator between( T from, T to ) { - CompositeGenerator generators; - generators.add( new BetweenGenerator( from, to ) ); - return generators; - } - - template - CompositeGenerator values( T val1, T val2 ) { - CompositeGenerator generators; - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - generators.add( valuesGen ); - return generators; - } - - template - CompositeGenerator values( T val1, T val2, T val3 ){ - CompositeGenerator generators; - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - valuesGen->add( val3 ); - generators.add( valuesGen ); - return generators; - } - - template - CompositeGenerator values( T val1, T val2, T val3, T val4 ) { - CompositeGenerator generators; - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - valuesGen->add( val3 ); - valuesGen->add( val4 ); - generators.add( valuesGen ); - return generators; - } - -} // end namespace Generators - -using namespace Generators; - -} // end namespace Catch - -#define INTERNAL_CATCH_LINESTR2( line ) #line -#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) - -#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) - -// #included from: internal/catch_interfaces_exception.h -#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED - -#include -// #included from: catch_interfaces_registry_hub.h -#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED - -#include - -namespace Catch { - - class TestCase; - struct ITestCaseRegistry; - struct IExceptionTranslatorRegistry; - struct IExceptionTranslator; - struct IReporterRegistry; - struct IReporterFactory; - - struct IRegistryHub { - virtual ~IRegistryHub(); - - virtual IReporterRegistry const& getReporterRegistry() const = 0; - virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; - }; - - struct IMutableRegistryHub { - virtual ~IMutableRegistryHub(); - virtual void registerReporter( std::string const& name, IReporterFactory* factory ) = 0; - virtual void registerTest( TestCase const& testInfo ) = 0; - virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; - }; - - IRegistryHub& getRegistryHub(); - IMutableRegistryHub& getMutableRegistryHub(); - void cleanUp(); - std::string translateActiveException(); - -} - - -namespace Catch { - - typedef std::string(*exceptionTranslateFunction)(); - - struct IExceptionTranslator { - virtual ~IExceptionTranslator(); - virtual std::string translate() const = 0; - }; - - struct IExceptionTranslatorRegistry { - virtual ~IExceptionTranslatorRegistry(); - - virtual std::string translateActiveException() const = 0; - }; - - class ExceptionTranslatorRegistrar { - template - class ExceptionTranslator : public IExceptionTranslator { - public: - - ExceptionTranslator( std::string(*translateFunction)( T& ) ) - : m_translateFunction( translateFunction ) - {} - - virtual std::string translate() const { - try { - throw; - } - catch( T& ex ) { - return m_translateFunction( ex ); - } - } - - protected: - std::string(*m_translateFunction)( T& ); - }; - - public: - template - ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { - getMutableRegistryHub().registerTranslator - ( new ExceptionTranslator( translateFunction ) ); - } - }; -} - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) \ - static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ); \ - namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ) ); }\ - static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ) - -// #included from: internal/catch_approx.hpp -#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED - -#include -#include - -namespace Catch { -namespace Detail { - - class Approx { - public: - explicit Approx ( double value ) - : m_epsilon( std::numeric_limits::epsilon()*100 ), - m_scale( 1.0 ), - m_value( value ) - {} - - Approx( Approx const& other ) - : m_epsilon( other.m_epsilon ), - m_scale( other.m_scale ), - m_value( other.m_value ) - {} - - static Approx custom() { - return Approx( 0 ); - } - - Approx operator()( double value ) { - Approx approx( value ); - approx.epsilon( m_epsilon ); - approx.scale( m_scale ); - return approx; - } - - friend bool operator == ( double lhs, Approx const& rhs ) { - // Thanks to Richard Harris for his help refining this formula - return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) ); - } - - friend bool operator == ( Approx const& lhs, double rhs ) { - return operator==( rhs, lhs ); - } - - friend bool operator != ( double lhs, Approx const& rhs ) { - return !operator==( lhs, rhs ); - } - - friend bool operator != ( Approx const& lhs, double rhs ) { - return !operator==( rhs, lhs ); - } - - Approx& epsilon( double newEpsilon ) { - m_epsilon = newEpsilon; - return *this; - } - - Approx& scale( double newScale ) { - m_scale = newScale; - return *this; - } - - std::string toString() const { - std::ostringstream oss; - oss << "Approx( " << Catch::toString( m_value ) << " )"; - return oss.str(); - } - - private: - double m_epsilon; - double m_scale; - double m_value; - }; -} - -template<> -inline std::string toString( Detail::Approx const& value ) { - return value.toString(); -} - -} // end namespace Catch - -// #included from: internal/catch_matchers.hpp -#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED - -namespace Catch { -namespace Matchers { - namespace Impl { - - template - struct Matcher : SharedImpl - { - typedef ExpressionT ExpressionType; - - virtual ~Matcher() {} - virtual Ptr clone() const = 0; - virtual bool match( ExpressionT const& expr ) const = 0; - virtual std::string toString() const = 0; - }; - - template - struct MatcherImpl : Matcher { - - virtual Ptr > clone() const { - return Ptr >( new DerivedT( static_cast( *this ) ) ); - } - }; - - namespace Generic { - - template - class AllOf : public MatcherImpl, ExpressionT> { - public: - - AllOf() {} - AllOf( AllOf const& other ) : m_matchers( other.m_matchers ) {} - - AllOf& add( Matcher const& matcher ) { - m_matchers.push_back( matcher.clone() ); - return *this; - } - virtual bool match( ExpressionT const& expr ) const - { - for( std::size_t i = 0; i < m_matchers.size(); ++i ) - if( !m_matchers[i]->match( expr ) ) - return false; - return true; - } - virtual std::string toString() const { - std::ostringstream oss; - oss << "( "; - for( std::size_t i = 0; i < m_matchers.size(); ++i ) { - if( i != 0 ) - oss << " and "; - oss << m_matchers[i]->toString(); - } - oss << " )"; - return oss.str(); - } - - private: - std::vector > > m_matchers; - }; - - template - class AnyOf : public MatcherImpl, ExpressionT> { - public: - - AnyOf() {} - AnyOf( AnyOf const& other ) : m_matchers( other.m_matchers ) {} - - AnyOf& add( Matcher const& matcher ) { - m_matchers.push_back( matcher.clone() ); - return *this; - } - virtual bool match( ExpressionT const& expr ) const - { - for( std::size_t i = 0; i < m_matchers.size(); ++i ) - if( m_matchers[i]->match( expr ) ) - return true; - return false; - } - virtual std::string toString() const { - std::ostringstream oss; - oss << "( "; - for( std::size_t i = 0; i < m_matchers.size(); ++i ) { - if( i != 0 ) - oss << " or "; - oss << m_matchers[i]->toString(); - } - oss << " )"; - return oss.str(); - } - - private: - std::vector > > m_matchers; - }; - - } - - namespace StdString { - - inline std::string makeString( std::string const& str ) { return str; } - inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); } - - struct Equals : MatcherImpl { - Equals( std::string const& str ) : m_str( str ){} - Equals( Equals const& other ) : m_str( other.m_str ){} - - virtual ~Equals(); - - virtual bool match( std::string const& expr ) const { - return m_str == expr; - } - virtual std::string toString() const { - return "equals: \"" + m_str + "\""; - } - - std::string m_str; - }; - - struct Contains : MatcherImpl { - Contains( std::string const& substr ) : m_substr( substr ){} - Contains( Contains const& other ) : m_substr( other.m_substr ){} - - virtual ~Contains(); - - virtual bool match( std::string const& expr ) const { - return expr.find( m_substr ) != std::string::npos; - } - virtual std::string toString() const { - return "contains: \"" + m_substr + "\""; - } - - std::string m_substr; - }; - - struct StartsWith : MatcherImpl { - StartsWith( std::string const& substr ) : m_substr( substr ){} - StartsWith( StartsWith const& other ) : m_substr( other.m_substr ){} - - virtual ~StartsWith(); - - virtual bool match( std::string const& expr ) const { - return expr.find( m_substr ) == 0; - } - virtual std::string toString() const { - return "starts with: \"" + m_substr + "\""; - } - - std::string m_substr; - }; - - struct EndsWith : MatcherImpl { - EndsWith( std::string const& substr ) : m_substr( substr ){} - EndsWith( EndsWith const& other ) : m_substr( other.m_substr ){} - - virtual ~EndsWith(); - - virtual bool match( std::string const& expr ) const { - return expr.find( m_substr ) == expr.size() - m_substr.size(); - } - virtual std::string toString() const { - return "ends with: \"" + m_substr + "\""; - } - - std::string m_substr; - }; - } // namespace StdString - } // namespace Impl - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - template - inline Impl::Generic::AllOf AllOf( Impl::Matcher const& m1, - Impl::Matcher const& m2 ) { - return Impl::Generic::AllOf().add( m1 ).add( m2 ); - } - template - inline Impl::Generic::AllOf AllOf( Impl::Matcher const& m1, - Impl::Matcher const& m2, - Impl::Matcher const& m3 ) { - return Impl::Generic::AllOf().add( m1 ).add( m2 ).add( m3 ); - } - template - inline Impl::Generic::AnyOf AnyOf( Impl::Matcher const& m1, - Impl::Matcher const& m2 ) { - return Impl::Generic::AnyOf().add( m1 ).add( m2 ); - } - template - inline Impl::Generic::AnyOf AnyOf( Impl::Matcher const& m1, - Impl::Matcher const& m2, - Impl::Matcher const& m3 ) { - return Impl::Generic::AnyOf().add( m1 ).add( m2 ).add( m3 ); - } - - inline Impl::StdString::Equals Equals( std::string const& str ) { - return Impl::StdString::Equals( str ); - } - inline Impl::StdString::Equals Equals( const char* str ) { - return Impl::StdString::Equals( Impl::StdString::makeString( str ) ); - } - inline Impl::StdString::Contains Contains( std::string const& substr ) { - return Impl::StdString::Contains( substr ); - } - inline Impl::StdString::Contains Contains( const char* substr ) { - return Impl::StdString::Contains( Impl::StdString::makeString( substr ) ); - } - inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) { - return Impl::StdString::StartsWith( substr ); - } - inline Impl::StdString::StartsWith StartsWith( const char* substr ) { - return Impl::StdString::StartsWith( Impl::StdString::makeString( substr ) ); - } - inline Impl::StdString::EndsWith EndsWith( std::string const& substr ) { - return Impl::StdString::EndsWith( substr ); - } - inline Impl::StdString::EndsWith EndsWith( const char* substr ) { - return Impl::StdString::EndsWith( Impl::StdString::makeString( substr ) ); - } - -} // namespace Matchers - -using namespace Matchers; - -} // namespace Catch - -// #included from: internal/catch_interfaces_tag_alias_registry.h -#define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED - -// #included from: catch_tag_alias.h -#define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED - -#include - -namespace Catch { - - struct TagAlias { - TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {} - - std::string tag; - SourceLineInfo lineInfo; - }; - - struct RegistrarForTagAliases { - RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - }; - -} // end namespace Catch - -#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } -// #included from: catch_option.hpp -#define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED - -namespace Catch { - - // An optional type - template - class Option { - public: - Option() : nullableValue( NULL ) {} - Option( T const& _value ) - : nullableValue( new( storage ) T( _value ) ) - {} - Option( Option const& _other ) - : nullableValue( _other ? new( storage ) T( *_other ) : NULL ) - {} - - ~Option() { - reset(); - } - - Option& operator= ( Option const& _other ) { - if( &_other != this ) { - reset(); - if( _other ) - nullableValue = new( storage ) T( *_other ); - } - return *this; - } - Option& operator = ( T const& _value ) { - reset(); - nullableValue = new( storage ) T( _value ); - return *this; - } - - void reset() { - if( nullableValue ) - nullableValue->~T(); - nullableValue = NULL; - } - - T& operator*() { return *nullableValue; } - T const& operator*() const { return *nullableValue; } - T* operator->() { return nullableValue; } - const T* operator->() const { return nullableValue; } - - T valueOr( T const& defaultValue ) const { - return nullableValue ? *nullableValue : defaultValue; - } - - bool some() const { return nullableValue != NULL; } - bool none() const { return nullableValue == NULL; } - - bool operator !() const { return nullableValue == NULL; } - operator SafeBool::type() const { - return SafeBool::makeSafe( some() ); - } - - private: - T* nullableValue; - char storage[sizeof(T)]; - }; - -} // end namespace Catch - -namespace Catch { - - struct ITagAliasRegistry { - virtual ~ITagAliasRegistry(); - virtual Option find( std::string const& alias ) const = 0; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; - - static ITagAliasRegistry const& get(); - }; - -} // end namespace Catch - -// These files are included here so the single_include script doesn't put them -// in the conditionally compiled sections -// #included from: internal/catch_test_case_info.h -#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED - -#include -#include - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - struct ITestCase; - - struct TestCaseInfo { - enum SpecialProperties{ - None = 0, - IsHidden = 1 << 1, - ShouldFail = 1 << 2, - MayFail = 1 << 3, - Throws = 1 << 4 - }; - - TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::set const& _tags, - SourceLineInfo const& _lineInfo ); - - TestCaseInfo( TestCaseInfo const& other ); - - bool isHidden() const; - bool throws() const; - bool okToFail() const; - bool expectedToFail() const; - - std::string name; - std::string className; - std::string description; - std::set tags; - std::set lcaseTags; - std::string tagsAsString; - SourceLineInfo lineInfo; - SpecialProperties properties; - }; - - class TestCase : public TestCaseInfo { - public: - - TestCase( ITestCase* testCase, TestCaseInfo const& info ); - TestCase( TestCase const& other ); - - TestCase withName( std::string const& _newName ) const; - - void invoke() const; - - TestCaseInfo const& getTestCaseInfo() const; - - void swap( TestCase& other ); - bool operator == ( TestCase const& other ) const; - bool operator < ( TestCase const& other ) const; - TestCase& operator = ( TestCase const& other ); - - private: - Ptr test; - }; - - TestCase makeTestCase( ITestCase* testCase, - std::string const& className, - std::string const& name, - std::string const& description, - SourceLineInfo const& lineInfo ); -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - - -#ifdef __OBJC__ -// #included from: internal/catch_objc.hpp -#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED - -#import - -#include - -// NB. Any general catch headers included here must be included -// in catch.hpp first to make sure they are included by the single -// header for non obj-usage - -/////////////////////////////////////////////////////////////////////////////// -// This protocol is really only here for (self) documenting purposes, since -// all its methods are optional. -@protocol OcFixture - -@optional - --(void) setUp; --(void) tearDown; - -@end - -namespace Catch { - - class OcMethod : public SharedImpl { - - public: - OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} - - virtual void invoke() const { - id obj = [[m_cls alloc] init]; - - performOptionalSelector( obj, @selector(setUp) ); - performOptionalSelector( obj, m_sel ); - performOptionalSelector( obj, @selector(tearDown) ); - - arcSafeRelease( obj ); - } - private: - virtual ~OcMethod() {} - - Class m_cls; - SEL m_sel; - }; - - namespace Detail{ - - inline std::string getAnnotation( Class cls, - std::string const& annotationName, - std::string const& testCaseName ) { - NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; - SEL sel = NSSelectorFromString( selStr ); - arcSafeRelease( selStr ); - id value = performOptionalSelector( cls, sel ); - if( value ) - return [(NSString*)value UTF8String]; - return ""; - } - } - - inline size_t registerTestMethods() { - size_t noTestMethods = 0; - int noClasses = objc_getClassList( NULL, 0 ); - - Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); - objc_getClassList( classes, noClasses ); - - for( int c = 0; c < noClasses; c++ ) { - Class cls = classes[c]; - { - u_int count; - Method* methods = class_copyMethodList( cls, &count ); - for( u_int m = 0; m < count ; m++ ) { - SEL selector = method_getName(methods[m]); - std::string methodName = sel_getName(selector); - if( startsWith( methodName, "Catch_TestCase_" ) ) { - std::string testCaseName = methodName.substr( 15 ); - std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); - std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); - const char* className = class_getName( cls ); - - getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) ); - noTestMethods++; - } - } - free(methods); - } - } - return noTestMethods; - } - - namespace Matchers { - namespace Impl { - namespace NSStringMatchers { - - template - struct StringHolder : MatcherImpl{ - StringHolder( NSString* substr ) : m_substr( [substr copy] ){} - StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} - StringHolder() { - arcSafeRelease( m_substr ); - } - - NSString* m_substr; - }; - - struct Equals : StringHolder { - Equals( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str isEqualToString:m_substr]; - } - - virtual std::string toString() const { - return "equals string: " + Catch::toString( m_substr ); - } - }; - - struct Contains : StringHolder { - Contains( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location != NSNotFound; - } - - virtual std::string toString() const { - return "contains string: " + Catch::toString( m_substr ); - } - }; - - struct StartsWith : StringHolder { - StartsWith( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == 0; - } - - virtual std::string toString() const { - return "starts with: " + Catch::toString( m_substr ); - } - }; - struct EndsWith : StringHolder { - EndsWith( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == [str length] - [m_substr length]; - } - - virtual std::string toString() const { - return "ends with: " + Catch::toString( m_substr ); - } - }; - - } // namespace NSStringMatchers - } // namespace Impl - - inline Impl::NSStringMatchers::Equals - Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } - - inline Impl::NSStringMatchers::Contains - Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } - - inline Impl::NSStringMatchers::StartsWith - StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } - - inline Impl::NSStringMatchers::EndsWith - EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } - - } // namespace Matchers - - using namespace Matchers; - -} // namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define OC_TEST_CASE( name, desc )\ -+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \ -{\ -return @ name; \ -}\ -+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \ -{ \ -return @ desc; \ -} \ --(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test ) - -#endif - -#ifdef CATCH_IMPL -// #included from: internal/catch_impl.hpp -#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED - -// Collect all the implementation files together here -// These are the equivalent of what would usually be cpp files - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wweak-vtables" -#endif - -// #included from: ../catch_runner.hpp -#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED - -// #included from: internal/catch_commandline.hpp -#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED - -// #included from: catch_config.hpp -#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED - -// #included from: catch_test_spec_parser.hpp -#define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -// #included from: catch_test_spec.hpp -#define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -#include -#include - -namespace Catch { - - class TestSpec { - struct Pattern : SharedImpl<> { - virtual ~Pattern(); - virtual bool matches( TestCaseInfo const& testCase ) const = 0; - }; - class NamePattern : public Pattern { - enum WildcardPosition { - NoWildcard = 0, - WildcardAtStart = 1, - WildcardAtEnd = 2, - WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd - }; - - public: - NamePattern( std::string const& name ) : m_name( toLower( name ) ), m_wildcard( NoWildcard ) { - if( startsWith( m_name, "*" ) ) { - m_name = m_name.substr( 1 ); - m_wildcard = WildcardAtStart; - } - if( endsWith( m_name, "*" ) ) { - m_name = m_name.substr( 0, m_name.size()-1 ); - m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); - } - } - virtual ~NamePattern(); - virtual bool matches( TestCaseInfo const& testCase ) const { - switch( m_wildcard ) { - case NoWildcard: - return m_name == toLower( testCase.name ); - case WildcardAtStart: - return endsWith( toLower( testCase.name ), m_name ); - case WildcardAtEnd: - return startsWith( toLower( testCase.name ), m_name ); - case WildcardAtBothEnds: - return contains( toLower( testCase.name ), m_name ); - } - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif - throw std::logic_error( "Unknown enum" ); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - } - private: - std::string m_name; - WildcardPosition m_wildcard; - }; - class TagPattern : public Pattern { - public: - TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} - virtual ~TagPattern(); - virtual bool matches( TestCaseInfo const& testCase ) const { - return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); - } - private: - std::string m_tag; - }; - class ExcludedPattern : public Pattern { - public: - ExcludedPattern( Ptr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} - virtual ~ExcludedPattern(); - virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } - private: - Ptr m_underlyingPattern; - }; - - struct Filter { - std::vector > m_patterns; - - bool matches( TestCaseInfo const& testCase ) const { - // All patterns in a filter must match for the filter to be a match - for( std::vector >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) - if( !(*it)->matches( testCase ) ) - return false; - return true; - } - }; - - public: - bool hasFilters() const { - return !m_filters.empty(); - } - bool matches( TestCaseInfo const& testCase ) const { - // A TestSpec matches if any filter matches - for( std::vector::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) - if( it->matches( testCase ) ) - return true; - return false; - } - - private: - std::vector m_filters; - - friend class TestSpecParser; - }; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -namespace Catch { - - class TestSpecParser { - enum Mode{ None, Name, QuotedName, Tag }; - Mode m_mode; - bool m_exclusion; - std::size_t m_start, m_pos; - std::string m_arg; - TestSpec::Filter m_currentFilter; - TestSpec m_testSpec; - ITagAliasRegistry const* m_tagAliases; - - public: - TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} - - TestSpecParser& parse( std::string const& arg ) { - m_mode = None; - m_exclusion = false; - m_start = std::string::npos; - m_arg = m_tagAliases->expandAliases( arg ); - for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) - visitChar( m_arg[m_pos] ); - if( m_mode == Name ) - addPattern(); - return *this; - } - TestSpec testSpec() { - addFilter(); - return m_testSpec; - } - private: - void visitChar( char c ) { - if( m_mode == None ) { - switch( c ) { - case ' ': return; - case '~': m_exclusion = true; return; - case '[': return startNewMode( Tag, ++m_pos ); - case '"': return startNewMode( QuotedName, ++m_pos ); - default: startNewMode( Name, m_pos ); break; - } - } - if( m_mode == Name ) { - if( c == ',' ) { - addPattern(); - addFilter(); - } - else if( c == '[' ) { - if( subString() == "exclude:" ) - m_exclusion = true; - else - addPattern(); - startNewMode( Tag, ++m_pos ); - } - } - else if( m_mode == QuotedName && c == '"' ) - addPattern(); - else if( m_mode == Tag && c == ']' ) - addPattern(); - } - void startNewMode( Mode mode, std::size_t start ) { - m_mode = mode; - m_start = start; - } - std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); } - template - void addPattern() { - std::string token = subString(); - if( startsWith( token, "exclude:" ) ) { - m_exclusion = true; - token = token.substr( 8 ); - } - if( !token.empty() ) { - Ptr pattern = new T( token ); - if( m_exclusion ) - pattern = new TestSpec::ExcludedPattern( pattern ); - m_currentFilter.m_patterns.push_back( pattern ); - } - m_exclusion = false; - m_mode = None; - } - void addFilter() { - if( !m_currentFilter.m_patterns.empty() ) { - m_testSpec.m_filters.push_back( m_currentFilter ); - m_currentFilter = TestSpec::Filter(); - } - } - }; - inline TestSpec parseTestSpec( std::string const& arg ) { - return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); - } - -} // namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// #included from: catch_interfaces_config.h -#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED - -#include -#include -#include - -namespace Catch { - - struct Verbosity { enum Level { - NoOutput = 0, - Quiet, - Normal - }; }; - - struct WarnAbout { enum What { - Nothing = 0x00, - NoAssertions = 0x01 - }; }; - - struct ShowDurations { enum OrNot { - DefaultForReporter, - Always, - Never - }; }; - struct RunTests { enum InWhatOrder { - InDeclarationOrder, - InLexicographicalOrder, - InRandomOrder - }; }; - - class TestSpec; - - struct IConfig : IShared { - - virtual ~IConfig(); - - virtual bool allowThrows() const = 0; - virtual std::ostream& stream() const = 0; - virtual std::string name() const = 0; - virtual bool includeSuccessfulResults() const = 0; - virtual bool shouldDebugBreak() const = 0; - virtual bool warnAboutMissingAssertions() const = 0; - virtual int abortAfter() const = 0; - virtual bool showInvisibles() const = 0; - virtual ShowDurations::OrNot showDurations() const = 0; - virtual TestSpec const& testSpec() const = 0; - virtual RunTests::InWhatOrder runOrder() const = 0; - virtual unsigned int rngSeed() const = 0; - virtual bool forceColour() const = 0; - }; -} - -// #included from: catch_stream.h -#define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED - -#include - -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - class Stream { - public: - Stream(); - Stream( std::streambuf* _streamBuf, bool _isOwned ); - void release(); - - std::streambuf* streamBuf; - - private: - bool isOwned; - }; - - std::ostream& cout(); - std::ostream& cerr(); -} - -#include -#include -#include -#include -#include - -#ifndef CATCH_CONFIG_CONSOLE_WIDTH -#define CATCH_CONFIG_CONSOLE_WIDTH 80 -#endif - -namespace Catch { - - struct ConfigData { - - ConfigData() - : listTests( false ), - listTags( false ), - listReporters( false ), - listTestNamesOnly( false ), - showSuccessfulTests( false ), - shouldDebugBreak( false ), - noThrow( false ), - showHelp( false ), - showInvisibles( false ), - forceColour( false ), - abortAfter( -1 ), - rngSeed( 0 ), - verbosity( Verbosity::Normal ), - warnings( WarnAbout::Nothing ), - showDurations( ShowDurations::DefaultForReporter ), - runOrder( RunTests::InDeclarationOrder ) - {} - - bool listTests; - bool listTags; - bool listReporters; - bool listTestNamesOnly; - - bool showSuccessfulTests; - bool shouldDebugBreak; - bool noThrow; - bool showHelp; - bool showInvisibles; - bool forceColour; - - int abortAfter; - unsigned int rngSeed; - - Verbosity::Level verbosity; - WarnAbout::What warnings; - ShowDurations::OrNot showDurations; - RunTests::InWhatOrder runOrder; - - std::string reporterName; - std::string outputFilename; - std::string name; - std::string processName; - - std::vector testsOrTags; - }; - - class Config : public SharedImpl { - private: - Config( Config const& other ); - Config& operator = ( Config const& other ); - virtual void dummy(); - public: - - Config() - : m_os( Catch::cout().rdbuf() ) - {} - - Config( ConfigData const& data ) - : m_data( data ), - m_os( Catch::cout().rdbuf() ) - { - if( !data.testsOrTags.empty() ) { - TestSpecParser parser( ITagAliasRegistry::get() ); - for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) - parser.parse( data.testsOrTags[i] ); - m_testSpec = parser.testSpec(); - } - } - - virtual ~Config() { - m_os.rdbuf( Catch::cout().rdbuf() ); - m_stream.release(); - } - - void setFilename( std::string const& filename ) { - m_data.outputFilename = filename; - } - - std::string const& getFilename() const { - return m_data.outputFilename ; - } - - bool listTests() const { return m_data.listTests; } - bool listTestNamesOnly() const { return m_data.listTestNamesOnly; } - bool listTags() const { return m_data.listTags; } - bool listReporters() const { return m_data.listReporters; } - - std::string getProcessName() const { return m_data.processName; } - - bool shouldDebugBreak() const { return m_data.shouldDebugBreak; } - - void setStreamBuf( std::streambuf* buf ) { - m_os.rdbuf( buf ? buf : Catch::cout().rdbuf() ); - } - - void useStream( std::string const& streamName ) { - Stream stream = createStream( streamName ); - setStreamBuf( stream.streamBuf ); - m_stream.release(); - m_stream = stream; - } - - std::string getReporterName() const { return m_data.reporterName; } - - int abortAfter() const { return m_data.abortAfter; } - - TestSpec const& testSpec() const { return m_testSpec; } - - bool showHelp() const { return m_data.showHelp; } - bool showInvisibles() const { return m_data.showInvisibles; } - - // IConfig interface - virtual bool allowThrows() const { return !m_data.noThrow; } - virtual std::ostream& stream() const { return m_os; } - virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } - virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; } - virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } - virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; } - virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; } - virtual unsigned int rngSeed() const { return m_data.rngSeed; } - virtual bool forceColour() const { return m_data.forceColour; } - - private: - ConfigData m_data; - - Stream m_stream; - mutable std::ostream m_os; - TestSpec m_testSpec; - }; - -} // end namespace Catch - -// #included from: catch_clara.h -#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED - -// Use Catch's value for console width (store Clara's off to the side, if present) -#ifdef CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH -#undef CLARA_CONFIG_CONSOLE_WIDTH -#endif -#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH - -// Declare Clara inside the Catch namespace -#define STITCH_CLARA_OPEN_NAMESPACE namespace Catch { -// #included from: ../external/clara.h - -// Only use header guard if we are not using an outer namespace -#if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE) - -#ifndef STITCH_CLARA_OPEN_NAMESPACE -#define TWOBLUECUBES_CLARA_H_INCLUDED -#define STITCH_CLARA_OPEN_NAMESPACE -#define STITCH_CLARA_CLOSE_NAMESPACE -#else -#define STITCH_CLARA_CLOSE_NAMESPACE } -#endif - -#define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE - -// ----------- #included from tbc_text_format.h ----------- - -// Only use header guard if we are not using an outer namespace -#if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE) -#ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE -#define TBC_TEXT_FORMAT_H_INCLUDED -#endif - -#include -#include -#include - -// Use optional outer namespace -#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE -namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE { -#endif - -namespace Tbc { - -#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH - const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; -#else - const unsigned int consoleWidth = 80; -#endif - - struct TextAttributes { - TextAttributes() - : initialIndent( std::string::npos ), - indent( 0 ), - width( consoleWidth-1 ), - tabChar( '\t' ) - {} - - TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } - TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } - TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } - TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } - - std::size_t initialIndent; // indent of first line, or npos - std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos - std::size_t width; // maximum width of text, including indent. Longer text will wrap - char tabChar; // If this char is seen the indent is changed to current pos - }; - - class Text { - public: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - if( lines.size() >= 1000 ) { - lines.push_back( "... message truncated due to excessive size" ); - return; - } - std::size_t tabPos = std::string::npos; - std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); - std::size_t pos = remainder.find_first_of( '\n' ); - if( pos <= width ) { - width = pos; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - - if( width == remainder.size() ) { - spliceLine( indent, remainder, width ); - } - else if( remainder[width] == '\n' ) { - spliceLine( indent, remainder, width ); - if( width <= 1 || remainder.size() != 1 ) - remainder = remainder.substr( 1 ); - indent = _attr.indent; - } - else { - pos = remainder.find_last_of( wrappableChars, width ); - if( pos != std::string::npos && pos > 0 ) { - spliceLine( indent, remainder, pos ); - if( remainder[0] == ' ' ) - remainder = remainder.substr( 1 ); - } - else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; - } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; - } - } - } - - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); - } - - typedef std::vector::const_iterator const_iterator; - - const_iterator begin() const { return lines.begin(); } - const_iterator end() const { return lines.end(); } - std::string const& last() const { return lines.back(); } - std::size_t size() const { return lines.size(); } - std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - std::string toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - - private: - std::string str; - TextAttributes attr; - std::vector lines; - }; - -} // end namespace Tbc - -#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE -} // end outer namespace -#endif - -#endif // TBC_TEXT_FORMAT_H_INCLUDED - -// ----------- end of #include from tbc_text_format.h ----------- -// ........... back in /Users/philnash/Dev/OSS/Clara/srcs/clara.h - -#undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE - -#include -#include -#include -#include - -// Use optional outer namespace -#ifdef STITCH_CLARA_OPEN_NAMESPACE -STITCH_CLARA_OPEN_NAMESPACE -#endif - -namespace Clara { - - struct UnpositionalTag {}; - - extern UnpositionalTag _; - -#ifdef CLARA_CONFIG_MAIN - UnpositionalTag _; -#endif - - namespace Detail { - -#ifdef CLARA_CONSOLE_WIDTH - const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; -#else - const unsigned int consoleWidth = 80; -#endif - - using namespace Tbc; - - inline bool startsWith( std::string const& str, std::string const& prefix ) { - return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix; - } - - template struct RemoveConstRef{ typedef T type; }; - template struct RemoveConstRef{ typedef T type; }; - template struct RemoveConstRef{ typedef T type; }; - template struct RemoveConstRef{ typedef T type; }; - - template struct IsBool { static const bool value = false; }; - template<> struct IsBool { static const bool value = true; }; - - template - void convertInto( std::string const& _source, T& _dest ) { - std::stringstream ss; - ss << _source; - ss >> _dest; - if( ss.fail() ) - throw std::runtime_error( "Unable to convert " + _source + " to destination type" ); - } - inline void convertInto( std::string const& _source, std::string& _dest ) { - _dest = _source; - } - inline void convertInto( std::string const& _source, bool& _dest ) { - std::string sourceLC = _source; - std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower ); - if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" ) - _dest = true; - else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" ) - _dest = false; - else - throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" ); - } - inline void convertInto( bool _source, bool& _dest ) { - _dest = _source; - } - template - inline void convertInto( bool, T& ) { - throw std::runtime_error( "Invalid conversion" ); - } - - template - struct IArgFunction { - virtual ~IArgFunction() {} -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - IArgFunction() = default; - IArgFunction( IArgFunction const& ) = default; -# endif - virtual void set( ConfigT& config, std::string const& value ) const = 0; - virtual void setFlag( ConfigT& config ) const = 0; - virtual bool takesArg() const = 0; - virtual IArgFunction* clone() const = 0; - }; - - template - class BoundArgFunction { - public: - BoundArgFunction() : functionObj( NULL ) {} - BoundArgFunction( IArgFunction* _functionObj ) : functionObj( _functionObj ) {} - BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : NULL ) {} - BoundArgFunction& operator = ( BoundArgFunction const& other ) { - IArgFunction* newFunctionObj = other.functionObj ? other.functionObj->clone() : NULL; - delete functionObj; - functionObj = newFunctionObj; - return *this; - } - ~BoundArgFunction() { delete functionObj; } - - void set( ConfigT& config, std::string const& value ) const { - functionObj->set( config, value ); - } - void setFlag( ConfigT& config ) const { - functionObj->setFlag( config ); - } - bool takesArg() const { return functionObj->takesArg(); } - - bool isSet() const { - return functionObj != NULL; - } - private: - IArgFunction* functionObj; - }; - - template - struct NullBinder : IArgFunction{ - virtual void set( C&, std::string const& ) const {} - virtual void setFlag( C& ) const {} - virtual bool takesArg() const { return true; } - virtual IArgFunction* clone() const { return new NullBinder( *this ); } - }; - - template - struct BoundDataMember : IArgFunction{ - BoundDataMember( M C::* _member ) : member( _member ) {} - virtual void set( C& p, std::string const& stringValue ) const { - convertInto( stringValue, p.*member ); - } - virtual void setFlag( C& p ) const { - convertInto( true, p.*member ); - } - virtual bool takesArg() const { return !IsBool::value; } - virtual IArgFunction* clone() const { return new BoundDataMember( *this ); } - M C::* member; - }; - template - struct BoundUnaryMethod : IArgFunction{ - BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {} - virtual void set( C& p, std::string const& stringValue ) const { - typename RemoveConstRef::type value; - convertInto( stringValue, value ); - (p.*member)( value ); - } - virtual void setFlag( C& p ) const { - typename RemoveConstRef::type value; - convertInto( true, value ); - (p.*member)( value ); - } - virtual bool takesArg() const { return !IsBool::value; } - virtual IArgFunction* clone() const { return new BoundUnaryMethod( *this ); } - void (C::*member)( M ); - }; - template - struct BoundNullaryMethod : IArgFunction{ - BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {} - virtual void set( C& p, std::string const& stringValue ) const { - bool value; - convertInto( stringValue, value ); - if( value ) - (p.*member)(); - } - virtual void setFlag( C& p ) const { - (p.*member)(); - } - virtual bool takesArg() const { return false; } - virtual IArgFunction* clone() const { return new BoundNullaryMethod( *this ); } - void (C::*member)(); - }; - - template - struct BoundUnaryFunction : IArgFunction{ - BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {} - virtual void set( C& obj, std::string const& stringValue ) const { - bool value; - convertInto( stringValue, value ); - if( value ) - function( obj ); - } - virtual void setFlag( C& p ) const { - function( p ); - } - virtual bool takesArg() const { return false; } - virtual IArgFunction* clone() const { return new BoundUnaryFunction( *this ); } - void (*function)( C& ); - }; - - template - struct BoundBinaryFunction : IArgFunction{ - BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {} - virtual void set( C& obj, std::string const& stringValue ) const { - typename RemoveConstRef::type value; - convertInto( stringValue, value ); - function( obj, value ); - } - virtual void setFlag( C& obj ) const { - typename RemoveConstRef::type value; - convertInto( true, value ); - function( obj, value ); - } - virtual bool takesArg() const { return !IsBool::value; } - virtual IArgFunction* clone() const { return new BoundBinaryFunction( *this ); } - void (*function)( C&, T ); - }; - - } // namespace Detail - - struct Parser { - Parser() : separators( " \t=:" ) {} - - struct Token { - enum Type { Positional, ShortOpt, LongOpt }; - Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {} - Type type; - std::string data; - }; - - void parseIntoTokens( int argc, char const * const * argv, std::vector& tokens ) const { - const std::string doubleDash = "--"; - for( int i = 1; i < argc && argv[i] != doubleDash; ++i ) - parseIntoTokens( argv[i] , tokens); - } - void parseIntoTokens( std::string arg, std::vector& tokens ) const { - while( !arg.empty() ) { - Parser::Token token( Parser::Token::Positional, arg ); - arg = ""; - if( token.data[0] == '-' ) { - if( token.data.size() > 1 && token.data[1] == '-' ) { - token = Parser::Token( Parser::Token::LongOpt, token.data.substr( 2 ) ); - } - else { - token = Parser::Token( Parser::Token::ShortOpt, token.data.substr( 1 ) ); - if( token.data.size() > 1 && separators.find( token.data[1] ) == std::string::npos ) { - arg = "-" + token.data.substr( 1 ); - token.data = token.data.substr( 0, 1 ); - } - } - } - if( token.type != Parser::Token::Positional ) { - std::size_t pos = token.data.find_first_of( separators ); - if( pos != std::string::npos ) { - arg = token.data.substr( pos+1 ); - token.data = token.data.substr( 0, pos ); - } - } - tokens.push_back( token ); - } - } - std::string separators; - }; - - template - struct CommonArgProperties { - CommonArgProperties() {} - CommonArgProperties( Detail::BoundArgFunction const& _boundField ) : boundField( _boundField ) {} - - Detail::BoundArgFunction boundField; - std::string description; - std::string detail; - std::string placeholder; // Only value if boundField takes an arg - - bool takesArg() const { - return !placeholder.empty(); - } - void validate() const { - if( !boundField.isSet() ) - throw std::logic_error( "option not bound" ); - } - }; - struct OptionArgProperties { - std::vector shortNames; - std::string longName; - - bool hasShortName( std::string const& shortName ) const { - return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end(); - } - bool hasLongName( std::string const& _longName ) const { - return _longName == longName; - } - }; - struct PositionalArgProperties { - PositionalArgProperties() : position( -1 ) {} - int position; // -1 means non-positional (floating) - - bool isFixedPositional() const { - return position != -1; - } - }; - - template - class CommandLine { - - struct Arg : CommonArgProperties, OptionArgProperties, PositionalArgProperties { - Arg() {} - Arg( Detail::BoundArgFunction const& _boundField ) : CommonArgProperties( _boundField ) {} - - using CommonArgProperties::placeholder; // !TBD - - std::string dbgName() const { - if( !longName.empty() ) - return "--" + longName; - if( !shortNames.empty() ) - return "-" + shortNames[0]; - return "positional args"; - } - std::string commands() const { - std::ostringstream oss; - bool first = true; - std::vector::const_iterator it = shortNames.begin(), itEnd = shortNames.end(); - for(; it != itEnd; ++it ) { - if( first ) - first = false; - else - oss << ", "; - oss << "-" << *it; - } - if( !longName.empty() ) { - if( !first ) - oss << ", "; - oss << "--" << longName; - } - if( !placeholder.empty() ) - oss << " <" << placeholder << ">"; - return oss.str(); - } - }; - - // NOTE: std::auto_ptr is deprecated in c++11/c++0x -#if defined(__cplusplus) && __cplusplus > 199711L - typedef std::unique_ptr ArgAutoPtr; -#else - typedef std::auto_ptr ArgAutoPtr; -#endif - - friend void addOptName( Arg& arg, std::string const& optName ) - { - if( optName.empty() ) - return; - if( Detail::startsWith( optName, "--" ) ) { - if( !arg.longName.empty() ) - throw std::logic_error( "Only one long opt may be specified. '" - + arg.longName - + "' already specified, now attempting to add '" - + optName + "'" ); - arg.longName = optName.substr( 2 ); - } - else if( Detail::startsWith( optName, "-" ) ) - arg.shortNames.push_back( optName.substr( 1 ) ); - else - throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" ); - } - friend void setPositionalArg( Arg& arg, int position ) - { - arg.position = position; - } - - class ArgBuilder { - public: - ArgBuilder( Arg* arg ) : m_arg( arg ) {} - - // Bind a non-boolean data member (requires placeholder string) - template - void bind( M C::* field, std::string const& placeholder ) { - m_arg->boundField = new Detail::BoundDataMember( field ); - m_arg->placeholder = placeholder; - } - // Bind a boolean data member (no placeholder required) - template - void bind( bool C::* field ) { - m_arg->boundField = new Detail::BoundDataMember( field ); - } - - // Bind a method taking a single, non-boolean argument (requires a placeholder string) - template - void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) { - m_arg->boundField = new Detail::BoundUnaryMethod( unaryMethod ); - m_arg->placeholder = placeholder; - } - - // Bind a method taking a single, boolean argument (no placeholder string required) - template - void bind( void (C::* unaryMethod)( bool ) ) { - m_arg->boundField = new Detail::BoundUnaryMethod( unaryMethod ); - } - - // Bind a method that takes no arguments (will be called if opt is present) - template - void bind( void (C::* nullaryMethod)() ) { - m_arg->boundField = new Detail::BoundNullaryMethod( nullaryMethod ); - } - - // Bind a free function taking a single argument - the object to operate on (no placeholder string required) - template - void bind( void (* unaryFunction)( C& ) ) { - m_arg->boundField = new Detail::BoundUnaryFunction( unaryFunction ); - } - - // Bind a free function taking a single argument - the object to operate on (requires a placeholder string) - template - void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) { - m_arg->boundField = new Detail::BoundBinaryFunction( binaryFunction ); - m_arg->placeholder = placeholder; - } - - ArgBuilder& describe( std::string const& description ) { - m_arg->description = description; - return *this; - } - ArgBuilder& detail( std::string const& detail ) { - m_arg->detail = detail; - return *this; - } - - protected: - Arg* m_arg; - }; - - class OptBuilder : public ArgBuilder { - public: - OptBuilder( Arg* arg ) : ArgBuilder( arg ) {} - OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {} - - OptBuilder& operator[]( std::string const& optName ) { - addOptName( *ArgBuilder::m_arg, optName ); - return *this; - } - }; - - public: - - CommandLine() - : m_boundProcessName( new Detail::NullBinder() ), - m_highestSpecifiedArgPosition( 0 ), - m_throwOnUnrecognisedTokens( false ) - {} - CommandLine( CommandLine const& other ) - : m_boundProcessName( other.m_boundProcessName ), - m_options ( other.m_options ), - m_positionalArgs( other.m_positionalArgs ), - m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ), - m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens ) - { - if( other.m_floatingArg.get() ) - m_floatingArg.reset( new Arg( *other.m_floatingArg ) ); - } - - CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) { - m_throwOnUnrecognisedTokens = shouldThrow; - return *this; - } - - OptBuilder operator[]( std::string const& optName ) { - m_options.push_back( Arg() ); - addOptName( m_options.back(), optName ); - OptBuilder builder( &m_options.back() ); - return builder; - } - - ArgBuilder operator[]( int position ) { - m_positionalArgs.insert( std::make_pair( position, Arg() ) ); - if( position > m_highestSpecifiedArgPosition ) - m_highestSpecifiedArgPosition = position; - setPositionalArg( m_positionalArgs[position], position ); - ArgBuilder builder( &m_positionalArgs[position] ); - return builder; - } - - // Invoke this with the _ instance - ArgBuilder operator[]( UnpositionalTag ) { - if( m_floatingArg.get() ) - throw std::logic_error( "Only one unpositional argument can be added" ); - m_floatingArg.reset( new Arg() ); - ArgBuilder builder( m_floatingArg.get() ); - return builder; - } - - template - void bindProcessName( M C::* field ) { - m_boundProcessName = new Detail::BoundDataMember( field ); - } - template - void bindProcessName( void (C::*_unaryMethod)( M ) ) { - m_boundProcessName = new Detail::BoundUnaryMethod( _unaryMethod ); - } - - void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const { - typename std::vector::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it; - std::size_t maxWidth = 0; - for( it = itBegin; it != itEnd; ++it ) - maxWidth = (std::max)( maxWidth, it->commands().size() ); - - for( it = itBegin; it != itEnd; ++it ) { - Detail::Text usage( it->commands(), Detail::TextAttributes() - .setWidth( maxWidth+indent ) - .setIndent( indent ) ); - Detail::Text desc( it->description, Detail::TextAttributes() - .setWidth( width - maxWidth - 3 ) ); - - for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) { - std::string usageCol = i < usage.size() ? usage[i] : ""; - os << usageCol; - - if( i < desc.size() && !desc[i].empty() ) - os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' ) - << desc[i]; - os << "\n"; - } - } - } - std::string optUsage() const { - std::ostringstream oss; - optUsage( oss ); - return oss.str(); - } - - void argSynopsis( std::ostream& os ) const { - for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) { - if( i > 1 ) - os << " "; - typename std::map::const_iterator it = m_positionalArgs.find( i ); - if( it != m_positionalArgs.end() ) - os << "<" << it->second.placeholder << ">"; - else if( m_floatingArg.get() ) - os << "<" << m_floatingArg->placeholder << ">"; - else - throw std::logic_error( "non consecutive positional arguments with no floating args" ); - } - // !TBD No indication of mandatory args - if( m_floatingArg.get() ) { - if( m_highestSpecifiedArgPosition > 1 ) - os << " "; - os << "[<" << m_floatingArg->placeholder << "> ...]"; - } - } - std::string argSynopsis() const { - std::ostringstream oss; - argSynopsis( oss ); - return oss.str(); - } - - void usage( std::ostream& os, std::string const& procName ) const { - validate(); - os << "usage:\n " << procName << " "; - argSynopsis( os ); - if( !m_options.empty() ) { - os << " [options]\n\nwhere options are: \n"; - optUsage( os, 2 ); - } - os << "\n"; - } - std::string usage( std::string const& procName ) const { - std::ostringstream oss; - usage( oss, procName ); - return oss.str(); - } - - ConfigT parse( int argc, char const * const * argv ) const { - ConfigT config; - parseInto( argc, argv, config ); - return config; - } - - std::vector parseInto( int argc, char const * const * argv, ConfigT& config ) const { - std::string processName = argv[0]; - std::size_t lastSlash = processName.find_last_of( "/\\" ); - if( lastSlash != std::string::npos ) - processName = processName.substr( lastSlash+1 ); - m_boundProcessName.set( config, processName ); - std::vector tokens; - Parser parser; - parser.parseIntoTokens( argc, argv, tokens ); - return populate( tokens, config ); - } - - std::vector populate( std::vector const& tokens, ConfigT& config ) const { - validate(); - std::vector unusedTokens = populateOptions( tokens, config ); - unusedTokens = populateFixedArgs( unusedTokens, config ); - unusedTokens = populateFloatingArgs( unusedTokens, config ); - return unusedTokens; - } - - std::vector populateOptions( std::vector const& tokens, ConfigT& config ) const { - std::vector unusedTokens; - std::vector errors; - for( std::size_t i = 0; i < tokens.size(); ++i ) { - Parser::Token const& token = tokens[i]; - typename std::vector::const_iterator it = m_options.begin(), itEnd = m_options.end(); - for(; it != itEnd; ++it ) { - Arg const& arg = *it; - - try { - if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) || - ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) { - if( arg.takesArg() ) { - if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional ) - errors.push_back( "Expected argument to option: " + token.data ); - else - arg.boundField.set( config, tokens[++i].data ); - } - else { - arg.boundField.setFlag( config ); - } - break; - } - } - catch( std::exception& ex ) { - errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); - } - } - if( it == itEnd ) { - if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) - unusedTokens.push_back( token ); - else if( errors.empty() && m_throwOnUnrecognisedTokens ) - errors.push_back( "unrecognised option: " + token.data ); - } - } - if( !errors.empty() ) { - std::ostringstream oss; - for( std::vector::const_iterator it = errors.begin(), itEnd = errors.end(); - it != itEnd; - ++it ) { - if( it != errors.begin() ) - oss << "\n"; - oss << *it; - } - throw std::runtime_error( oss.str() ); - } - return unusedTokens; - } - std::vector populateFixedArgs( std::vector const& tokens, ConfigT& config ) const { - std::vector unusedTokens; - int position = 1; - for( std::size_t i = 0; i < tokens.size(); ++i ) { - Parser::Token const& token = tokens[i]; - typename std::map::const_iterator it = m_positionalArgs.find( position ); - if( it != m_positionalArgs.end() ) - it->second.boundField.set( config, token.data ); - else - unusedTokens.push_back( token ); - if( token.type == Parser::Token::Positional ) - position++; - } - return unusedTokens; - } - std::vector populateFloatingArgs( std::vector const& tokens, ConfigT& config ) const { - if( !m_floatingArg.get() ) - return tokens; - std::vector unusedTokens; - for( std::size_t i = 0; i < tokens.size(); ++i ) { - Parser::Token const& token = tokens[i]; - if( token.type == Parser::Token::Positional ) - m_floatingArg->boundField.set( config, token.data ); - else - unusedTokens.push_back( token ); - } - return unusedTokens; - } - - void validate() const - { - if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() ) - throw std::logic_error( "No options or arguments specified" ); - - for( typename std::vector::const_iterator it = m_options.begin(), - itEnd = m_options.end(); - it != itEnd; ++it ) - it->validate(); - } - - private: - Detail::BoundArgFunction m_boundProcessName; - std::vector m_options; - std::map m_positionalArgs; - ArgAutoPtr m_floatingArg; - int m_highestSpecifiedArgPosition; - bool m_throwOnUnrecognisedTokens; - }; - -} // end namespace Clara - -STITCH_CLARA_CLOSE_NAMESPACE -#undef STITCH_CLARA_OPEN_NAMESPACE -#undef STITCH_CLARA_CLOSE_NAMESPACE - -#endif // TWOBLUECUBES_CLARA_H_INCLUDED -#undef STITCH_CLARA_OPEN_NAMESPACE - -// Restore Clara's value for console width, if present -#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#endif - -#include - -namespace Catch { - - inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; } - inline void abortAfterX( ConfigData& config, int x ) { - if( x < 1 ) - throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" ); - config.abortAfter = x; - } - inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); } - - inline void addWarning( ConfigData& config, std::string const& _warning ) { - if( _warning == "NoAssertions" ) - config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); - else - throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" ); - } - inline void setOrder( ConfigData& config, std::string const& order ) { - if( startsWith( "declared", order ) ) - config.runOrder = RunTests::InDeclarationOrder; - else if( startsWith( "lexical", order ) ) - config.runOrder = RunTests::InLexicographicalOrder; - else if( startsWith( "random", order ) ) - config.runOrder = RunTests::InRandomOrder; - else - throw std::runtime_error( "Unrecognised ordering: '" + order + "'" ); - } - inline void setRngSeed( ConfigData& config, std::string const& seed ) { - if( seed == "time" ) { - config.rngSeed = static_cast( std::time(0) ); - } - else { - std::stringstream ss; - ss << seed; - ss >> config.rngSeed; - if( ss.fail() ) - throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" ); - } - } - inline void setVerbosity( ConfigData& config, int level ) { - // !TBD: accept strings? - config.verbosity = static_cast( level ); - } - inline void setShowDurations( ConfigData& config, bool _showDurations ) { - config.showDurations = _showDurations - ? ShowDurations::Always - : ShowDurations::Never; - } - inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) { - std::ifstream f( _filename.c_str() ); - if( !f.is_open() ) - throw std::domain_error( "Unable to load input file: " + _filename ); - - std::string line; - while( std::getline( f, line ) ) { - line = trim(line); - if( !line.empty() && !startsWith( line, "#" ) ) - addTestOrTags( config, "\"" + line + "\"," ); - } - } - - inline Clara::CommandLine makeCommandLineParser() { - - using namespace Clara; - CommandLine cli; - - cli.bindProcessName( &ConfigData::processName ); - - cli["-?"]["-h"]["--help"] - .describe( "display usage information" ) - .bind( &ConfigData::showHelp ); - - cli["-l"]["--list-tests"] - .describe( "list all/matching test cases" ) - .bind( &ConfigData::listTests ); - - cli["-t"]["--list-tags"] - .describe( "list all/matching tags" ) - .bind( &ConfigData::listTags ); - - cli["-s"]["--success"] - .describe( "include successful tests in output" ) - .bind( &ConfigData::showSuccessfulTests ); - - cli["-b"]["--break"] - .describe( "break into debugger on failure" ) - .bind( &ConfigData::shouldDebugBreak ); - - cli["-e"]["--nothrow"] - .describe( "skip exception tests" ) - .bind( &ConfigData::noThrow ); - - cli["-i"]["--invisibles"] - .describe( "show invisibles (tabs, newlines)" ) - .bind( &ConfigData::showInvisibles ); - - cli["-o"]["--out"] - .describe( "output filename" ) - .bind( &ConfigData::outputFilename, "filename" ); - - cli["-r"]["--reporter"] -// .placeholder( "name[:filename]" ) - .describe( "reporter to use (defaults to console)" ) - .bind( &ConfigData::reporterName, "name" ); - - cli["-n"]["--name"] - .describe( "suite name" ) - .bind( &ConfigData::name, "name" ); - - cli["-a"]["--abort"] - .describe( "abort at first failure" ) - .bind( &abortAfterFirst ); - - cli["-x"]["--abortx"] - .describe( "abort after x failures" ) - .bind( &abortAfterX, "no. failures" ); - - cli["-w"]["--warn"] - .describe( "enable warnings" ) - .bind( &addWarning, "warning name" ); - -// - needs updating if reinstated -// cli.into( &setVerbosity ) -// .describe( "level of verbosity (0=no output)" ) -// .shortOpt( "v") -// .longOpt( "verbosity" ) -// .placeholder( "level" ); - - cli[_] - .describe( "which test or tests to use" ) - .bind( &addTestOrTags, "test name, pattern or tags" ); - - cli["-d"]["--durations"] - .describe( "show test durations" ) - .bind( &setShowDurations, "yes/no" ); - - cli["-f"]["--input-file"] - .describe( "load test names to run from a file" ) - .bind( &loadTestNamesFromFile, "filename" ); - - // Less common commands which don't have a short form - cli["--list-test-names-only"] - .describe( "list all/matching test cases names only" ) - .bind( &ConfigData::listTestNamesOnly ); - - cli["--list-reporters"] - .describe( "list all reporters" ) - .bind( &ConfigData::listReporters ); - - cli["--order"] - .describe( "test case order (defaults to decl)" ) - .bind( &setOrder, "decl|lex|rand" ); - - cli["--rng-seed"] - .describe( "set a specific seed for random numbers" ) - .bind( &setRngSeed, "'time'|number" ); - - cli["--force-colour"] - .describe( "force colourised output" ) - .bind( &ConfigData::forceColour ); - - return cli; - } - -} // end namespace Catch - -// #included from: internal/catch_list.hpp -#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED - -// #included from: catch_text.h -#define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED - -#define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH - -#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch -// #included from: ../external/tbc_text_format.h -// Only use header guard if we are not using an outer namespace -#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE -# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED -# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -# endif -# else -# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED -# endif -#endif -#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -#include -#include -#include - -// Use optional outer namespace -#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE -namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { -#endif - -namespace Tbc { - -#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH - const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; -#else - const unsigned int consoleWidth = 80; -#endif - - struct TextAttributes { - TextAttributes() - : initialIndent( std::string::npos ), - indent( 0 ), - width( consoleWidth-1 ), - tabChar( '\t' ) - {} - - TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } - TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } - TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } - TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } - - std::size_t initialIndent; // indent of first line, or npos - std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos - std::size_t width; // maximum width of text, including indent. Longer text will wrap - char tabChar; // If this char is seen the indent is changed to current pos - }; - - class Text { - public: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - if( lines.size() >= 1000 ) { - lines.push_back( "... message truncated due to excessive size" ); - return; - } - std::size_t tabPos = std::string::npos; - std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); - std::size_t pos = remainder.find_first_of( '\n' ); - if( pos <= width ) { - width = pos; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - - if( width == remainder.size() ) { - spliceLine( indent, remainder, width ); - } - else if( remainder[width] == '\n' ) { - spliceLine( indent, remainder, width ); - if( width <= 1 || remainder.size() != 1 ) - remainder = remainder.substr( 1 ); - indent = _attr.indent; - } - else { - pos = remainder.find_last_of( wrappableChars, width ); - if( pos != std::string::npos && pos > 0 ) { - spliceLine( indent, remainder, pos ); - if( remainder[0] == ' ' ) - remainder = remainder.substr( 1 ); - } - else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; - } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; - } - } - } - - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); - } - - typedef std::vector::const_iterator const_iterator; - - const_iterator begin() const { return lines.begin(); } - const_iterator end() const { return lines.end(); } - std::string const& last() const { return lines.back(); } - std::size_t size() const { return lines.size(); } - std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - std::string toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - - private: - std::string str; - TextAttributes attr; - std::vector lines; - }; - -} // end namespace Tbc - -#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE -} // end outer namespace -#endif - -#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE - -namespace Catch { - using Tbc::Text; - using Tbc::TextAttributes; -} - -// #included from: catch_console_colour.hpp -#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED - -namespace Catch { - - struct Colour { - enum Code { - None = 0, - - White, - Red, - Green, - Blue, - Cyan, - Yellow, - Grey, - - Bright = 0x10, - - BrightRed = Bright | Red, - BrightGreen = Bright | Green, - LightGrey = Bright | Grey, - BrightWhite = Bright | White, - - // By intention - FileName = LightGrey, - Warning = Yellow, - ResultError = BrightRed, - ResultSuccess = BrightGreen, - ResultExpectedFailure = Warning, - - Error = BrightRed, - Success = Green, - - OriginalExpression = Cyan, - ReconstructedExpression = Yellow, - - SecondaryText = LightGrey, - Headers = White - }; - - // Use constructed object for RAII guard - Colour( Code _colourCode ); - Colour( Colour const& other ); - ~Colour(); - - // Use static method for one-shot changes - static void use( Code _colourCode ); - - private: - bool m_moved; - }; - - inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; } - -} // end namespace Catch - -// #included from: catch_interfaces_reporter.h -#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED - -#include -#include -#include -#include - -namespace Catch -{ - struct ReporterConfig { - explicit ReporterConfig( Ptr const& _fullConfig ) - : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} - - ReporterConfig( Ptr const& _fullConfig, std::ostream& _stream ) - : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} - - std::ostream& stream() const { return *m_stream; } - Ptr fullConfig() const { return m_fullConfig; } - - private: - std::ostream* m_stream; - Ptr m_fullConfig; - }; - - struct ReporterPreferences { - ReporterPreferences() - : shouldRedirectStdOut( false ) - {} - - bool shouldRedirectStdOut; - }; - - template - struct LazyStat : Option { - LazyStat() : used( false ) {} - LazyStat& operator=( T const& _value ) { - Option::operator=( _value ); - used = false; - return *this; - } - void reset() { - Option::reset(); - used = false; - } - bool used; - }; - - struct TestRunInfo { - TestRunInfo( std::string const& _name ) : name( _name ) {} - std::string name; - }; - struct GroupInfo { - GroupInfo( std::string const& _name, - std::size_t _groupIndex, - std::size_t _groupsCount ) - : name( _name ), - groupIndex( _groupIndex ), - groupsCounts( _groupsCount ) - {} - - std::string name; - std::size_t groupIndex; - std::size_t groupsCounts; - }; - - struct AssertionStats { - AssertionStats( AssertionResult const& _assertionResult, - std::vector const& _infoMessages, - Totals const& _totals ) - : assertionResult( _assertionResult ), - infoMessages( _infoMessages ), - totals( _totals ) - { - if( assertionResult.hasMessage() ) { - // Copy message into messages list. - // !TBD This should have been done earlier, somewhere - MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); - builder << assertionResult.getMessage(); - builder.m_info.message = builder.m_stream.str(); - - infoMessages.push_back( builder.m_info ); - } - } - virtual ~AssertionStats(); - -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - AssertionStats( AssertionStats const& ) = default; - AssertionStats( AssertionStats && ) = default; - AssertionStats& operator = ( AssertionStats const& ) = default; - AssertionStats& operator = ( AssertionStats && ) = default; -# endif - - AssertionResult assertionResult; - std::vector infoMessages; - Totals totals; - }; - - struct SectionStats { - SectionStats( SectionInfo const& _sectionInfo, - Counts const& _assertions, - double _durationInSeconds, - bool _missingAssertions ) - : sectionInfo( _sectionInfo ), - assertions( _assertions ), - durationInSeconds( _durationInSeconds ), - missingAssertions( _missingAssertions ) - {} - virtual ~SectionStats(); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - SectionStats( SectionStats const& ) = default; - SectionStats( SectionStats && ) = default; - SectionStats& operator = ( SectionStats const& ) = default; - SectionStats& operator = ( SectionStats && ) = default; -# endif - - SectionInfo sectionInfo; - Counts assertions; - double durationInSeconds; - bool missingAssertions; - }; - - struct TestCaseStats { - TestCaseStats( TestCaseInfo const& _testInfo, - Totals const& _totals, - std::string const& _stdOut, - std::string const& _stdErr, - bool _aborting ) - : testInfo( _testInfo ), - totals( _totals ), - stdOut( _stdOut ), - stdErr( _stdErr ), - aborting( _aborting ) - {} - virtual ~TestCaseStats(); - -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - TestCaseStats( TestCaseStats const& ) = default; - TestCaseStats( TestCaseStats && ) = default; - TestCaseStats& operator = ( TestCaseStats const& ) = default; - TestCaseStats& operator = ( TestCaseStats && ) = default; -# endif - - TestCaseInfo testInfo; - Totals totals; - std::string stdOut; - std::string stdErr; - bool aborting; - }; - - struct TestGroupStats { - TestGroupStats( GroupInfo const& _groupInfo, - Totals const& _totals, - bool _aborting ) - : groupInfo( _groupInfo ), - totals( _totals ), - aborting( _aborting ) - {} - TestGroupStats( GroupInfo const& _groupInfo ) - : groupInfo( _groupInfo ), - aborting( false ) - {} - virtual ~TestGroupStats(); - -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - TestGroupStats( TestGroupStats const& ) = default; - TestGroupStats( TestGroupStats && ) = default; - TestGroupStats& operator = ( TestGroupStats const& ) = default; - TestGroupStats& operator = ( TestGroupStats && ) = default; -# endif - - GroupInfo groupInfo; - Totals totals; - bool aborting; - }; - - struct TestRunStats { - TestRunStats( TestRunInfo const& _runInfo, - Totals const& _totals, - bool _aborting ) - : runInfo( _runInfo ), - totals( _totals ), - aborting( _aborting ) - {} - virtual ~TestRunStats(); - -# ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS - TestRunStats( TestRunStats const& _other ) - : runInfo( _other.runInfo ), - totals( _other.totals ), - aborting( _other.aborting ) - {} -# else - TestRunStats( TestRunStats const& ) = default; - TestRunStats( TestRunStats && ) = default; - TestRunStats& operator = ( TestRunStats const& ) = default; - TestRunStats& operator = ( TestRunStats && ) = default; -# endif - - TestRunInfo runInfo; - Totals totals; - bool aborting; - }; - - struct IStreamingReporter : IShared { - virtual ~IStreamingReporter(); - - // Implementing class must also provide the following static method: - // static std::string getDescription(); - - virtual ReporterPreferences getPreferences() const = 0; - - virtual void noMatchingTestCases( std::string const& spec ) = 0; - - virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; - virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; - - virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; - virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; - - virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; - - // The return value indicates if the messages buffer should be cleared: - virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; - virtual void sectionEnded( SectionStats const& sectionStats ) = 0; - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; - virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; - - virtual void skipTest( TestCaseInfo const& testInfo ) = 0; - }; - - struct IReporterFactory { - virtual ~IReporterFactory(); - virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0; - virtual std::string getDescription() const = 0; - }; - - struct IReporterRegistry { - typedef std::map FactoryMap; - - virtual ~IReporterRegistry(); - virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const = 0; - virtual FactoryMap const& getFactories() const = 0; - }; - -} - -#include -#include - -namespace Catch { - - inline std::size_t listTests( Config const& config ) { - - TestSpec testSpec = config.testSpec(); - if( config.testSpec().hasFilters() ) - Catch::cout() << "Matching test cases:\n"; - else { - Catch::cout() << "All available test cases:\n"; - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); - } - - std::size_t matchedTests = 0; - TextAttributes nameAttr, tagsAttr; - nameAttr.setInitialIndent( 2 ).setIndent( 4 ); - tagsAttr.setIndent( 6 ); - - std::vector matchedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - matchedTests++; - TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); - Colour::Code colour = testCaseInfo.isHidden() - ? Colour::SecondaryText - : Colour::None; - Colour colourGuard( colour ); - - Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; - if( !testCaseInfo.tags.empty() ) - Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; - } - - if( !config.testSpec().hasFilters() ) - Catch::cout() << pluralise( matchedTests, "test case" ) << "\n" << std::endl; - else - Catch::cout() << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl; - return matchedTests; - } - - inline std::size_t listTestsNamesOnly( Config const& config ) { - TestSpec testSpec = config.testSpec(); - if( !config.testSpec().hasFilters() ) - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); - std::size_t matchedTests = 0; - std::vector matchedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - matchedTests++; - TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); - Catch::cout() << testCaseInfo.name << std::endl; - } - return matchedTests; - } - - struct TagInfo { - TagInfo() : count ( 0 ) {} - void add( std::string const& spelling ) { - ++count; - spellings.insert( spelling ); - } - std::string all() const { - std::string out; - for( std::set::const_iterator it = spellings.begin(), itEnd = spellings.end(); - it != itEnd; - ++it ) - out += "[" + *it + "]"; - return out; - } - std::set spellings; - std::size_t count; - }; - - inline std::size_t listTags( Config const& config ) { - TestSpec testSpec = config.testSpec(); - if( config.testSpec().hasFilters() ) - Catch::cout() << "Tags for matching test cases:\n"; - else { - Catch::cout() << "All available tags:\n"; - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); - } - - std::map tagCounts; - - std::vector matchedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - for( std::set::const_iterator tagIt = it->getTestCaseInfo().tags.begin(), - tagItEnd = it->getTestCaseInfo().tags.end(); - tagIt != tagItEnd; - ++tagIt ) { - std::string tagName = *tagIt; - std::string lcaseTagName = toLower( tagName ); - std::map::iterator countIt = tagCounts.find( lcaseTagName ); - if( countIt == tagCounts.end() ) - countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; - countIt->second.add( tagName ); - } - } - - for( std::map::const_iterator countIt = tagCounts.begin(), - countItEnd = tagCounts.end(); - countIt != countItEnd; - ++countIt ) { - std::ostringstream oss; - oss << " " << std::setw(2) << countIt->second.count << " "; - Text wrapper( countIt->second.all(), TextAttributes() - .setInitialIndent( 0 ) - .setIndent( oss.str().size() ) - .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); - Catch::cout() << oss.str() << wrapper << "\n"; - } - Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl; - return tagCounts.size(); - } - - inline std::size_t listReporters( Config const& /*config*/ ) { - Catch::cout() << "Available reporters:\n"; - IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); - IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it; - std::size_t maxNameLen = 0; - for(it = itBegin; it != itEnd; ++it ) - maxNameLen = (std::max)( maxNameLen, it->first.size() ); - - for(it = itBegin; it != itEnd; ++it ) { - Text wrapper( it->second->getDescription(), TextAttributes() - .setInitialIndent( 0 ) - .setIndent( 7+maxNameLen ) - .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); - Catch::cout() << " " - << it->first - << ":" - << std::string( maxNameLen - it->first.size() + 2, ' ' ) - << wrapper << "\n"; - } - Catch::cout() << std::endl; - return factories.size(); - } - - inline Option list( Config const& config ) { - Option listedCount; - if( config.listTests() ) - listedCount = listedCount.valueOr(0) + listTests( config ); - if( config.listTestNamesOnly() ) - listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); - if( config.listTags() ) - listedCount = listedCount.valueOr(0) + listTags( config ); - if( config.listReporters() ) - listedCount = listedCount.valueOr(0) + listReporters( config ); - return listedCount; - } - -} // end namespace Catch - -// #included from: internal/catch_runner_impl.hpp -#define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED - -// #included from: catch_test_case_tracker.hpp -#define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED - -#include -#include -#include - -namespace Catch { -namespace SectionTracking { - - class TrackedSection { - - typedef std::map TrackedSections; - - public: - enum RunState { - NotStarted, - Executing, - ExecutingChildren, - Completed - }; - - TrackedSection( std::string const& name, TrackedSection* parent ) - : m_name( name ), m_runState( NotStarted ), m_parent( parent ) - {} - - RunState runState() const { return m_runState; } - - TrackedSection* findChild( std::string const& childName ); - TrackedSection* acquireChild( std::string const& childName ); - - void enter() { - if( m_runState == NotStarted ) - m_runState = Executing; - } - void leave(); - - TrackedSection* getParent() { - return m_parent; - } - bool hasChildren() const { - return !m_children.empty(); - } - - private: - std::string m_name; - RunState m_runState; - TrackedSections m_children; - TrackedSection* m_parent; - }; - - inline TrackedSection* TrackedSection::findChild( std::string const& childName ) { - TrackedSections::iterator it = m_children.find( childName ); - return it != m_children.end() - ? &it->second - : NULL; - } - inline TrackedSection* TrackedSection::acquireChild( std::string const& childName ) { - if( TrackedSection* child = findChild( childName ) ) - return child; - m_children.insert( std::make_pair( childName, TrackedSection( childName, this ) ) ); - return findChild( childName ); - } - inline void TrackedSection::leave() { - for( TrackedSections::const_iterator it = m_children.begin(), itEnd = m_children.end(); - it != itEnd; - ++it ) - if( it->second.runState() != Completed ) { - m_runState = ExecutingChildren; - return; - } - m_runState = Completed; - } - - class TestCaseTracker { - public: - TestCaseTracker( std::string const& testCaseName ) - : m_testCase( testCaseName, NULL ), - m_currentSection( &m_testCase ), - m_completedASectionThisRun( false ) - {} - - bool enterSection( std::string const& name ) { - TrackedSection* child = m_currentSection->acquireChild( name ); - if( m_completedASectionThisRun || child->runState() == TrackedSection::Completed ) - return false; - - m_currentSection = child; - m_currentSection->enter(); - return true; - } - void leaveSection() { - m_currentSection->leave(); - m_currentSection = m_currentSection->getParent(); - assert( m_currentSection != NULL ); - m_completedASectionThisRun = true; - } - - bool currentSectionHasChildren() const { - return m_currentSection->hasChildren(); - } - bool isCompleted() const { - return m_testCase.runState() == TrackedSection::Completed; - } - - class Guard { - public: - Guard( TestCaseTracker& tracker ) : m_tracker( tracker ) { - m_tracker.enterTestCase(); - } - ~Guard() { - m_tracker.leaveTestCase(); - } - private: - Guard( Guard const& ); - void operator = ( Guard const& ); - TestCaseTracker& m_tracker; - }; - - private: - void enterTestCase() { - m_currentSection = &m_testCase; - m_completedASectionThisRun = false; - m_testCase.enter(); - } - void leaveTestCase() { - m_testCase.leave(); - } - - TrackedSection m_testCase; - TrackedSection* m_currentSection; - bool m_completedASectionThisRun; - }; - -} // namespace SectionTracking - -using SectionTracking::TestCaseTracker; - -} // namespace Catch - -// #included from: catch_fatal_condition.hpp -#define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED - -namespace Catch { - - // Report the error condition then exit the process - inline void fatal( std::string const& message, int exitCode ) { - IContext& context = Catch::getCurrentContext(); - IResultCapture* resultCapture = context.getResultCapture(); - resultCapture->handleFatalErrorCondition( message ); - - if( Catch::alwaysTrue() ) // avoids "no return" warnings - exit( exitCode ); - } - -} // namespace Catch - -#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// - -namespace Catch { - - struct FatalConditionHandler { - void reset() {} - }; - -} // namespace Catch - -#else // Not Windows - assumed to be POSIX compatible ////////////////////////// - -#include - -namespace Catch { - - struct SignalDefs { int id; const char* name; }; - extern SignalDefs signalDefs[]; - SignalDefs signalDefs[] = { - { SIGINT, "SIGINT - Terminal interrupt signal" }, - { SIGILL, "SIGILL - Illegal instruction signal" }, - { SIGFPE, "SIGFPE - Floating point error signal" }, - { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, - { SIGTERM, "SIGTERM - Termination request signal" }, - { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } - }; - - struct FatalConditionHandler { - - static void handleSignal( int sig ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - if( sig == signalDefs[i].id ) - fatal( signalDefs[i].name, -sig ); - fatal( "", -sig ); - } - - FatalConditionHandler() : m_isSet( true ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - signal( signalDefs[i].id, handleSignal ); - } - ~FatalConditionHandler() { - reset(); - } - void reset() { - if( m_isSet ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - signal( signalDefs[i].id, SIG_DFL ); - m_isSet = false; - } - } - - bool m_isSet; - }; - -} // namespace Catch - -#endif // not Windows - -#include -#include - -namespace Catch { - - class StreamRedirect { - - public: - StreamRedirect( std::ostream& stream, std::string& targetString ) - : m_stream( stream ), - m_prevBuf( stream.rdbuf() ), - m_targetString( targetString ) - { - stream.rdbuf( m_oss.rdbuf() ); - } - - ~StreamRedirect() { - m_targetString += m_oss.str(); - m_stream.rdbuf( m_prevBuf ); - } - - private: - std::ostream& m_stream; - std::streambuf* m_prevBuf; - std::ostringstream m_oss; - std::string& m_targetString; - }; - - /////////////////////////////////////////////////////////////////////////// - - class RunContext : public IResultCapture, public IRunner { - - RunContext( RunContext const& ); - void operator =( RunContext const& ); - - public: - - explicit RunContext( Ptr const& config, Ptr const& reporter ) - : m_runInfo( config->name() ), - m_context( getCurrentMutableContext() ), - m_activeTestCase( NULL ), - m_config( config ), - m_reporter( reporter ), - m_prevRunner( m_context.getRunner() ), - m_prevResultCapture( m_context.getResultCapture() ), - m_prevConfig( m_context.getConfig() ) - { - m_context.setRunner( this ); - m_context.setConfig( m_config ); - m_context.setResultCapture( this ); - m_reporter->testRunStarting( m_runInfo ); - } - - virtual ~RunContext() { - m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); - m_context.setRunner( m_prevRunner ); - m_context.setConfig( NULL ); - m_context.setResultCapture( m_prevResultCapture ); - m_context.setConfig( m_prevConfig ); - } - - void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) { - m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) ); - } - void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) { - m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) ); - } - - Totals runTest( TestCase const& testCase ) { - Totals prevTotals = m_totals; - - std::string redirectedCout; - std::string redirectedCerr; - - TestCaseInfo testInfo = testCase.getTestCaseInfo(); - - m_reporter->testCaseStarting( testInfo ); - - m_activeTestCase = &testCase; - m_testCaseTracker = TestCaseTracker( testInfo.name ); - - do { - do { - runCurrentTest( redirectedCout, redirectedCerr ); - } - while( !m_testCaseTracker->isCompleted() && !aborting() ); - } - while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); - - Totals deltaTotals = m_totals.delta( prevTotals ); - m_totals.testCases += deltaTotals.testCases; - m_reporter->testCaseEnded( TestCaseStats( testInfo, - deltaTotals, - redirectedCout, - redirectedCerr, - aborting() ) ); - - m_activeTestCase = NULL; - m_testCaseTracker.reset(); - - return deltaTotals; - } - - Ptr config() const { - return m_config; - } - - private: // IResultCapture - - virtual void assertionEnded( AssertionResult const& result ) { - if( result.getResultType() == ResultWas::Ok ) { - m_totals.assertions.passed++; - } - else if( !result.isOk() ) { - m_totals.assertions.failed++; - } - - if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) ) - m_messages.clear(); - - // Reset working state - m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); - m_lastResult = result; - } - - virtual bool sectionStarted ( - SectionInfo const& sectionInfo, - Counts& assertions - ) - { - std::ostringstream oss; - oss << sectionInfo.name << "@" << sectionInfo.lineInfo; - - if( !m_testCaseTracker->enterSection( oss.str() ) ) - return false; - - m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; - - m_reporter->sectionStarting( sectionInfo ); - - assertions = m_totals.assertions; - - return true; - } - bool testForMissingAssertions( Counts& assertions ) { - if( assertions.total() != 0 || - !m_config->warnAboutMissingAssertions() || - m_testCaseTracker->currentSectionHasChildren() ) - return false; - m_totals.assertions.failed++; - assertions.failed++; - return true; - } - - virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions, double _durationInSeconds ) { - /* if( std::uncaught_exception() ) { // XXX Hack that makes Catch not run in loop in certain situations - m_unfinishedSections.push_back( UnfinishedSections( info, prevAssertions, _durationInSeconds ) ); - return; - }*/ - - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions( assertions ); - - m_testCaseTracker->leaveSection(); - - m_reporter->sectionEnded( SectionStats( info, assertions, _durationInSeconds, missingAssertions ) ); - m_messages.clear(); - } - - virtual void pushScopedMessage( MessageInfo const& message ) { - m_messages.push_back( message ); - } - - virtual void popScopedMessage( MessageInfo const& message ) { - m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() ); - } - - virtual std::string getCurrentTestName() const { - return m_activeTestCase - ? m_activeTestCase->getTestCaseInfo().name - : ""; - } - - virtual const AssertionResult* getLastResult() const { - return &m_lastResult; - } - - virtual void handleFatalErrorCondition( std::string const& message ) { - ResultBuilder resultBuilder = makeUnexpectedResultBuilder(); - resultBuilder.setResultType( ResultWas::FatalErrorCondition ); - resultBuilder << message; - resultBuilder.captureExpression(); - - handleUnfinishedSections(); - - // Recreate section for test case (as we will lose the one that was in scope) - TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); - - Counts assertions; - assertions.failed = 1; - SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false ); - m_reporter->sectionEnded( testCaseSectionStats ); - - TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo(); - - Totals deltaTotals; - deltaTotals.testCases.failed = 1; - m_reporter->testCaseEnded( TestCaseStats( testInfo, - deltaTotals, - "", - "", - false ) ); - m_totals.testCases.failed++; - testGroupEnded( "", m_totals, 1, 1 ); - m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) ); - } - - public: - // !TBD We need to do this another way! - bool aborting() const { - return m_totals.assertions.failed == static_cast( m_config->abortAfter() ); - } - - private: - - void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) { - TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); - m_reporter->sectionStarting( testCaseSection ); - Counts prevAssertions = m_totals.assertions; - double duration = 0; - try { - m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); - TestCaseTracker::Guard guard( *m_testCaseTracker ); - - Timer timer; - timer.start(); - if( m_reporter->getPreferences().shouldRedirectStdOut ) { - StreamRedirect coutRedir( Catch::cout(), redirectedCout ); - StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr ); - invokeActiveTestCase(); - } - else { - invokeActiveTestCase(); - } - duration = timer.getElapsedSeconds(); - } - catch( TestFailureException& ) { - // This just means the test was aborted due to failure - } - catch(...) { - makeUnexpectedResultBuilder().useActiveException(); - } - handleUnfinishedSections(); - m_messages.clear(); - - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions( assertions ); - - if( testCaseInfo.okToFail() ) { - std::swap( assertions.failedButOk, assertions.failed ); - m_totals.assertions.failed -= assertions.failedButOk; - m_totals.assertions.failedButOk += assertions.failedButOk; - } - - SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions ); - m_reporter->sectionEnded( testCaseSectionStats ); - } - - void invokeActiveTestCase() { - FatalConditionHandler fatalConditionHandler; // Handle signals - m_activeTestCase->invoke(); - fatalConditionHandler.reset(); - } - - private: - - ResultBuilder makeUnexpectedResultBuilder() const { - return ResultBuilder( m_lastAssertionInfo.macroName.c_str(), - m_lastAssertionInfo.lineInfo, - m_lastAssertionInfo.capturedExpression.c_str(), - m_lastAssertionInfo.resultDisposition ); - } - - void handleUnfinishedSections() { - // If sections ended prematurely due to an exception we stored their - // infos here so we can tear them down outside the unwind process. - for( std::vector::const_reverse_iterator it = m_unfinishedSections.rbegin(), - itEnd = m_unfinishedSections.rend(); - it != itEnd; - ++it ) - sectionEnded( it->info, it->prevAssertions, it->durationInSeconds ); - m_unfinishedSections.clear(); - } - - struct UnfinishedSections { - UnfinishedSections( SectionInfo const& _info, Counts const& _prevAssertions, double _durationInSeconds ) - : info( _info ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) - {} - - SectionInfo info; - Counts prevAssertions; - double durationInSeconds; - }; - - TestRunInfo m_runInfo; - IMutableContext& m_context; - TestCase const* m_activeTestCase; - Option m_testCaseTracker; - AssertionResult m_lastResult; - - Ptr m_config; - Totals m_totals; - Ptr m_reporter; - std::vector m_messages; - IRunner* m_prevRunner; - IResultCapture* m_prevResultCapture; - Ptr m_prevConfig; - AssertionInfo m_lastAssertionInfo; - std::vector m_unfinishedSections; - }; - - IResultCapture& getResultCapture() { - if( IResultCapture* capture = getCurrentContext().getResultCapture() ) - return *capture; - else - throw std::logic_error( "No result capture instance" ); - } - -} // end namespace Catch - -// #included from: internal/catch_version.h -#define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED - -namespace Catch { - - // Versioning information - struct Version { - Version( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - std::string const& _branchName, - unsigned int _buildNumber ); - - unsigned int const majorVersion; - unsigned int const minorVersion; - unsigned int const patchNumber; - - // buildNumber is only used if branchName is not null - std::string const branchName; - unsigned int const buildNumber; - - friend std::ostream& operator << ( std::ostream& os, Version const& version ); - - private: - void operator=( Version const& ); - }; - - extern Version libraryVersion; -} - -#include -#include -#include - -namespace Catch { - - class Runner { - - public: - Runner( Ptr const& config ) - : m_config( config ) - { - openStream(); - makeReporter(); - } - - Totals runTests() { - - RunContext context( m_config.get(), m_reporter ); - - Totals totals; - - context.testGroupStarting( "all tests", 1, 1 ); // deprecated? - - TestSpec testSpec = m_config->testSpec(); - if( !testSpec.hasFilters() ) - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests - - std::vector testCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, testCases ); - - int testsRunForGroup = 0; - for( std::vector::const_iterator it = testCases.begin(), itEnd = testCases.end(); - it != itEnd; - ++it ) { - testsRunForGroup++; - if( m_testsAlreadyRun.find( *it ) == m_testsAlreadyRun.end() ) { - - if( context.aborting() ) - break; - - totals += context.runTest( *it ); - m_testsAlreadyRun.insert( *it ); - } - } - std::vector skippedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true ); - - for( std::vector::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end(); - it != itEnd; - ++it ) - m_reporter->skipTest( *it ); - - context.testGroupEnded( "all tests", totals, 1, 1 ); - return totals; - } - - private: - void openStream() { - // Open output file, if specified - if( !m_config->getFilename().empty() ) { - m_ofs.open( m_config->getFilename().c_str() ); - if( m_ofs.fail() ) { - std::ostringstream oss; - oss << "Unable to open file: '" << m_config->getFilename() << "'"; - throw std::domain_error( oss.str() ); - } - m_config->setStreamBuf( m_ofs.rdbuf() ); - } - } - void makeReporter() { - std::string reporterName = m_config->getReporterName().empty() - ? "console" - : m_config->getReporterName(); - - m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, m_config.get() ); - if( !m_reporter ) { - std::ostringstream oss; - oss << "No reporter registered with name: '" << reporterName << "'"; - throw std::domain_error( oss.str() ); - } - } - - private: - Ptr m_config; - std::ofstream m_ofs; - Ptr m_reporter; - std::set m_testsAlreadyRun; - }; - - class Session : NonCopyable { - static bool alreadyInstantiated; - - public: - - struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; }; - - Session() - : m_cli( makeCommandLineParser() ) { - if( alreadyInstantiated ) { - std::string msg = "Only one instance of Catch::Session can ever be used"; - Catch::cerr() << msg << std::endl; - throw std::logic_error( msg ); - } - alreadyInstantiated = true; - } - ~Session() { - Catch::cleanUp(); - } - - void showHelp( std::string const& processName ) { - Catch::cout() << "\nCatch v" << libraryVersion << "\n"; - - m_cli.usage( Catch::cout(), processName ); - Catch::cout() << "For more detail usage please see the project docs\n" << std::endl; - } - - int applyCommandLine( int argc, char* const argv[], OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) { - try { - m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail ); - m_unusedTokens = m_cli.parseInto( argc, argv, m_configData ); - if( m_configData.showHelp ) - showHelp( m_configData.processName ); - m_config.reset(); - } - catch( std::exception& ex ) { - { - Colour colourGuard( Colour::Red ); - Catch::cerr() - << "\nError(s) in input:\n" - << Text( ex.what(), TextAttributes().setIndent(2) ) - << "\n\n"; - } - m_cli.usage( Catch::cout(), m_configData.processName ); - return (std::numeric_limits::max)(); - } - return 0; - } - - void useConfigData( ConfigData const& _configData ) { - m_configData = _configData; - m_config.reset(); - } - - int run( int argc, char* const argv[] ) { - - int returnCode = applyCommandLine( argc, argv ); - if( returnCode == 0 ) - returnCode = run(); - return returnCode; - } - - int run() { - if( m_configData.showHelp ) - return 0; - - try - { - config(); // Force config to be constructed - - std::srand( m_configData.rngSeed ); - - Runner runner( m_config ); - - // Handle list request - if( Option listed = list( config() ) ) - return static_cast( *listed ); - - return static_cast( runner.runTests().assertions.failed ); - } - catch( std::exception& ex ) { - Catch::cerr() << ex.what() << std::endl; - return (std::numeric_limits::max)(); - } - } - - Clara::CommandLine const& cli() const { - return m_cli; - } - std::vector const& unusedTokens() const { - return m_unusedTokens; - } - ConfigData& configData() { - return m_configData; - } - Config& config() { - if( !m_config ) - m_config = new Config( m_configData ); - return *m_config; - } - - private: - Clara::CommandLine m_cli; - std::vector m_unusedTokens; - ConfigData m_configData; - Ptr m_config; - }; - - bool Session::alreadyInstantiated = false; - -} // end namespace Catch - -// #included from: catch_registry_hub.hpp -#define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED - -// #included from: catch_test_case_registry_impl.hpp -#define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace Catch { - - class TestRegistry : public ITestCaseRegistry { - struct LexSort { - bool operator() (TestCase i,TestCase j) const { return (i const& getAllTests() const { - return m_functionsInOrder; - } - - virtual std::vector const& getAllNonHiddenTests() const { - return m_nonHiddenFunctions; - } - - virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector& matchingTestCases, bool negated = false ) const { - - for( std::vector::const_iterator it = m_functionsInOrder.begin(), - itEnd = m_functionsInOrder.end(); - it != itEnd; - ++it ) { - bool includeTest = testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ); - if( includeTest != negated ) - matchingTestCases.push_back( *it ); - } - sortTests( config, matchingTestCases ); - } - - private: - - static void sortTests( IConfig const& config, std::vector& matchingTestCases ) { - - switch( config.runOrder() ) { - case RunTests::InLexicographicalOrder: - std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() ); - break; - case RunTests::InRandomOrder: - { - RandomNumberGenerator rng; - std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); - } - break; - case RunTests::InDeclarationOrder: - // already in declaration order - break; - } - } - std::set m_functions; - std::vector m_functionsInOrder; - std::vector m_nonHiddenFunctions; - size_t m_unnamedCount; - }; - - /////////////////////////////////////////////////////////////////////////// - - class FreeFunctionTestCase : public SharedImpl { - public: - - FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} - - virtual void invoke() const { - m_fun(); - } - - private: - virtual ~FreeFunctionTestCase(); - - TestFunction m_fun; - }; - - inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) { - std::string className = classOrQualifiedMethodName; - if( startsWith( className, "&" ) ) - { - std::size_t lastColons = className.rfind( "::" ); - std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); - if( penultimateColons == std::string::npos ) - penultimateColons = 1; - className = className.substr( penultimateColons, lastColons-penultimateColons ); - } - return className; - } - - /////////////////////////////////////////////////////////////////////////// - - AutoReg::AutoReg( TestFunction function, - SourceLineInfo const& lineInfo, - NameAndDesc const& nameAndDesc ) { - registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo ); - } - - AutoReg::~AutoReg() {} - - void AutoReg::registerTestCase( ITestCase* testCase, - char const* classOrQualifiedMethodName, - NameAndDesc const& nameAndDesc, - SourceLineInfo const& lineInfo ) { - - getMutableRegistryHub().registerTest - ( makeTestCase( testCase, - extractClassName( classOrQualifiedMethodName ), - nameAndDesc.name, - nameAndDesc.description, - lineInfo ) ); - } - -} // end namespace Catch - -// #included from: catch_reporter_registry.hpp -#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED - -#include - -namespace Catch { - - class ReporterRegistry : public IReporterRegistry { - - public: - - virtual ~ReporterRegistry() { - deleteAllValues( m_factories ); - } - - virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const { - FactoryMap::const_iterator it = m_factories.find( name ); - if( it == m_factories.end() ) - return NULL; - return it->second->create( ReporterConfig( config ) ); - } - - void registerReporter( std::string const& name, IReporterFactory* factory ) { - m_factories.insert( std::make_pair( name, factory ) ); - } - - FactoryMap const& getFactories() const { - return m_factories; - } - - private: - FactoryMap m_factories; - }; -} - -// #included from: catch_exception_translator_registry.hpp -#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED - -#ifdef __OBJC__ -#import "Foundation/Foundation.h" -#endif - -namespace Catch { - - class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { - public: - ~ExceptionTranslatorRegistry() { - deleteAll( m_translators ); - } - - virtual void registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( translator ); - } - - virtual std::string translateActiveException() const { - try { -#ifdef __OBJC__ - // In Objective-C try objective-c exceptions first - @try { - throw; - } - @catch (NSException *exception) { - return Catch::toString( [exception description] ); - } -#else - throw; -#endif - } - catch( TestFailureException& ) { - throw; - } - catch( std::exception& ex ) { - return ex.what(); - } - catch( std::string& msg ) { - return msg; - } - catch( const char* msg ) { - return msg; - } - catch(...) { - return tryTranslators( m_translators.begin() ); - } - } - - std::string tryTranslators( std::vector::const_iterator it ) const { - if( it == m_translators.end() ) - return "Unknown exception"; - - try { - return (*it)->translate(); - } - catch(...) { - return tryTranslators( it+1 ); - } - } - - private: - std::vector m_translators; - }; -} - -namespace Catch { - - namespace { - - class RegistryHub : public IRegistryHub, public IMutableRegistryHub { - - RegistryHub( RegistryHub const& ); - void operator=( RegistryHub const& ); - - public: // IRegistryHub - RegistryHub() { - } - virtual IReporterRegistry const& getReporterRegistry() const { - return m_reporterRegistry; - } - virtual ITestCaseRegistry const& getTestCaseRegistry() const { - return m_testCaseRegistry; - } - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() { - return m_exceptionTranslatorRegistry; - } - - public: // IMutableRegistryHub - virtual void registerReporter( std::string const& name, IReporterFactory* factory ) { - m_reporterRegistry.registerReporter( name, factory ); - } - virtual void registerTest( TestCase const& testInfo ) { - m_testCaseRegistry.registerTest( testInfo ); - } - virtual void registerTranslator( const IExceptionTranslator* translator ) { - m_exceptionTranslatorRegistry.registerTranslator( translator ); - } - - private: - TestRegistry m_testCaseRegistry; - ReporterRegistry m_reporterRegistry; - ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; - }; - - // Single, global, instance - inline RegistryHub*& getTheRegistryHub() { - static RegistryHub* theRegistryHub = NULL; - if( !theRegistryHub ) - theRegistryHub = new RegistryHub(); - return theRegistryHub; - } - } - - IRegistryHub& getRegistryHub() { - return *getTheRegistryHub(); - } - IMutableRegistryHub& getMutableRegistryHub() { - return *getTheRegistryHub(); - } - void cleanUp() { - delete getTheRegistryHub(); - getTheRegistryHub() = NULL; - cleanUpContext(); - } - std::string translateActiveException() { - return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); - } - -} // end namespace Catch - -// #included from: catch_notimplemented_exception.hpp -#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED - -#include - -namespace Catch { - - NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo ) - : m_lineInfo( lineInfo ) { - std::ostringstream oss; - oss << lineInfo << ": function "; - oss << "not implemented"; - m_what = oss.str(); - } - - const char* NotImplementedException::what() const CATCH_NOEXCEPT { - return m_what.c_str(); - } - -} // end namespace Catch - -// #included from: catch_context_impl.hpp -#define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED - -// #included from: catch_stream.hpp -#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED - -// #included from: catch_streambuf.h -#define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED - -#include - -namespace Catch { - - class StreamBufBase : public std::streambuf { - public: - virtual ~StreamBufBase() CATCH_NOEXCEPT; - }; -} - -#include -#include -#include - -namespace Catch { - - template - class StreamBufImpl : public StreamBufBase { - char data[bufferSize]; - WriterF m_writer; - - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); - } - - ~StreamBufImpl() CATCH_NOEXCEPT { - sync(); - } - - private: - int overflow( int c ) { - sync(); - - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast( c ) ) ); - else - sputc( static_cast( c ) ); - } - return 0; - } - - int sync() { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - struct OutputDebugWriter { - - void operator()( std::string const&str ) { - writeToDebugConsole( str ); - } - }; - - Stream::Stream() - : streamBuf( NULL ), isOwned( false ) - {} - - Stream::Stream( std::streambuf* _streamBuf, bool _isOwned ) - : streamBuf( _streamBuf ), isOwned( _isOwned ) - {} - - void Stream::release() { - if( isOwned ) { - delete streamBuf; - streamBuf = NULL; - isOwned = false; - } - } - -#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement this functions - std::ostream& cout() { - return std::cout; - } - std::ostream& cerr() { - return std::cerr; - } -#endif -} - -namespace Catch { - - class Context : public IMutableContext { - - Context() : m_config( NULL ), m_runner( NULL ), m_resultCapture( NULL ) {} - Context( Context const& ); - void operator=( Context const& ); - - public: // IContext - virtual IResultCapture* getResultCapture() { - return m_resultCapture; - } - virtual IRunner* getRunner() { - return m_runner; - } - virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) { - return getGeneratorsForCurrentTest() - .getGeneratorInfo( fileInfo, totalSize ) - .getCurrentIndex(); - } - virtual bool advanceGeneratorsForCurrentTest() { - IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); - return generators && generators->moveNext(); - } - - virtual Ptr getConfig() const { - return m_config; - } - - public: // IMutableContext - virtual void setResultCapture( IResultCapture* resultCapture ) { - m_resultCapture = resultCapture; - } - virtual void setRunner( IRunner* runner ) { - m_runner = runner; - } - virtual void setConfig( Ptr const& config ) { - m_config = config; - } - - friend IMutableContext& getCurrentMutableContext(); - - private: - IGeneratorsForTest* findGeneratorsForCurrentTest() { - std::string testName = getResultCapture()->getCurrentTestName(); - - std::map::const_iterator it = - m_generatorsByTestName.find( testName ); - return it != m_generatorsByTestName.end() - ? it->second - : NULL; - } - - IGeneratorsForTest& getGeneratorsForCurrentTest() { - IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); - if( !generators ) { - std::string testName = getResultCapture()->getCurrentTestName(); - generators = createGeneratorsForTest(); - m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); - } - return *generators; - } - - private: - Ptr m_config; - IRunner* m_runner; - IResultCapture* m_resultCapture; - std::map m_generatorsByTestName; - }; - - namespace { - Context* currentContext = NULL; - } - IMutableContext& getCurrentMutableContext() { - if( !currentContext ) - currentContext = new Context(); - return *currentContext; - } - IContext& getCurrentContext() { - return getCurrentMutableContext(); - } - - Stream createStream( std::string const& streamName ) { - if( streamName == "stdout" ) return Stream( Catch::cout().rdbuf(), false ); - if( streamName == "stderr" ) return Stream( Catch::cerr().rdbuf(), false ); - if( streamName == "debug" ) return Stream( new StreamBufImpl, true ); - - throw std::domain_error( "Unknown stream: " + streamName ); - } - - void cleanUpContext() { - delete currentContext; - currentContext = NULL; - } -} - -// #included from: catch_console_colour_impl.hpp -#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED - -namespace Catch { - namespace { - - struct IColourImpl { - virtual ~IColourImpl() {} - virtual void use( Colour::Code _colourCode ) = 0; - }; - - struct NoColourImpl : IColourImpl { - void use( Colour::Code ) {} - - static IColourImpl* instance() { - static NoColourImpl s_instance; - return &s_instance; - } - }; - - } // anon namespace -} // namespace Catch - -#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) -# ifdef CATCH_PLATFORM_WINDOWS -# define CATCH_CONFIG_COLOUR_WINDOWS -# else -# define CATCH_CONFIG_COLOUR_ANSI -# endif -#endif - -#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// - -#ifndef NOMINMAX -#define NOMINMAX -#endif - -#ifdef __AFXDLL -#include -#else -#include -#endif - -namespace Catch { -namespace { - - class Win32ColourImpl : public IColourImpl { - public: - Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) - { - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); - originalAttributes = csbiInfo.wAttributes; - } - - virtual void use( Colour::Code _colourCode ) { - switch( _colourCode ) { - case Colour::None: return setTextAttribute( originalAttributes ); - case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - case Colour::Red: return setTextAttribute( FOREGROUND_RED ); - case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); - case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); - case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); - case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); - case Colour::Grey: return setTextAttribute( 0 ); - - case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); - case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); - case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); - case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - - case Colour::Bright: throw std::logic_error( "not a colour" ); - } - } - - private: - void setTextAttribute( WORD _textAttribute ) { - SetConsoleTextAttribute( stdoutHandle, _textAttribute ); - } - HANDLE stdoutHandle; - WORD originalAttributes; - }; - - IColourImpl* platformColourInstance() { - static Win32ColourImpl s_instance; - return &s_instance; - } - -} // end anon namespace -} // end namespace Catch - -#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// - -#include - -namespace Catch { -namespace { - - // use POSIX/ ANSI console terminal codes - // Thanks to Adam Strzelecki for original contribution - // (http://github.com/nanoant) - // https://github.com/philsquared/Catch/pull/131 - class PosixColourImpl : public IColourImpl { - public: - virtual void use( Colour::Code _colourCode ) { - switch( _colourCode ) { - case Colour::None: - case Colour::White: return setColour( "[0m" ); - case Colour::Red: return setColour( "[0;31m" ); - case Colour::Green: return setColour( "[0;32m" ); - case Colour::Blue: return setColour( "[0:34m" ); - case Colour::Cyan: return setColour( "[0;36m" ); - case Colour::Yellow: return setColour( "[0;33m" ); - case Colour::Grey: return setColour( "[1;30m" ); - - case Colour::LightGrey: return setColour( "[0;37m" ); - case Colour::BrightRed: return setColour( "[1;31m" ); - case Colour::BrightGreen: return setColour( "[1;32m" ); - case Colour::BrightWhite: return setColour( "[1;37m" ); - - case Colour::Bright: throw std::logic_error( "not a colour" ); - } - } - static IColourImpl* instance() { - static PosixColourImpl s_instance; - return &s_instance; - } - - private: - void setColour( const char* _escapeCode ) { - Catch::cout() << '\033' << _escapeCode; - } - }; - - IColourImpl* platformColourInstance() { - Ptr config = getCurrentContext().getConfig(); - return (config && config->forceColour()) || isatty(STDOUT_FILENO) - ? PosixColourImpl::instance() - : NoColourImpl::instance(); - } - -} // end anon namespace -} // end namespace Catch - -#else // not Windows or ANSI /////////////////////////////////////////////// - -namespace Catch { - - static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } - -} // end namespace Catch - -#endif // Windows/ ANSI/ None - -namespace Catch { - - Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); } - Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast( _other ).m_moved = true; } - Colour::~Colour(){ if( !m_moved ) use( None ); } - - void Colour::use( Code _colourCode ) { - static IColourImpl* impl = isDebuggerActive() - ? NoColourImpl::instance() - : platformColourInstance(); - impl->use( _colourCode ); - } - -} // end namespace Catch - -// #included from: catch_generators_impl.hpp -#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED - -#include -#include -#include - -namespace Catch { - - struct GeneratorInfo : IGeneratorInfo { - - GeneratorInfo( std::size_t size ) - : m_size( size ), - m_currentIndex( 0 ) - {} - - bool moveNext() { - if( ++m_currentIndex == m_size ) { - m_currentIndex = 0; - return false; - } - return true; - } - - std::size_t getCurrentIndex() const { - return m_currentIndex; - } - - std::size_t m_size; - std::size_t m_currentIndex; - }; - - /////////////////////////////////////////////////////////////////////////// - - class GeneratorsForTest : public IGeneratorsForTest { - - public: - ~GeneratorsForTest() { - deleteAll( m_generatorsInOrder ); - } - - IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) { - std::map::const_iterator it = m_generatorsByName.find( fileInfo ); - if( it == m_generatorsByName.end() ) { - IGeneratorInfo* info = new GeneratorInfo( size ); - m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); - m_generatorsInOrder.push_back( info ); - return *info; - } - return *it->second; - } - - bool moveNext() { - std::vector::const_iterator it = m_generatorsInOrder.begin(); - std::vector::const_iterator itEnd = m_generatorsInOrder.end(); - for(; it != itEnd; ++it ) { - if( (*it)->moveNext() ) - return true; - } - return false; - } - - private: - std::map m_generatorsByName; - std::vector m_generatorsInOrder; - }; - - IGeneratorsForTest* createGeneratorsForTest() - { - return new GeneratorsForTest(); - } - -} // end namespace Catch - -// #included from: catch_assertionresult.hpp -#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED - -namespace Catch { - - AssertionInfo::AssertionInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - std::string const& _capturedExpression, - ResultDisposition::Flags _resultDisposition ) - : macroName( _macroName ), - lineInfo( _lineInfo ), - capturedExpression( _capturedExpression ), - resultDisposition( _resultDisposition ) - {} - - AssertionResult::AssertionResult() {} - - AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) - : m_info( info ), - m_resultData( data ) - {} - - AssertionResult::~AssertionResult() {} - - // Result was a success - bool AssertionResult::succeeded() const { - return Catch::isOk( m_resultData.resultType ); - } - - // Result was a success, or failure is suppressed - bool AssertionResult::isOk() const { - return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); - } - - ResultWas::OfType AssertionResult::getResultType() const { - return m_resultData.resultType; - } - - bool AssertionResult::hasExpression() const { - return !m_info.capturedExpression.empty(); - } - - bool AssertionResult::hasMessage() const { - return !m_resultData.message.empty(); - } - - std::string AssertionResult::getExpression() const { - if( isFalseTest( m_info.resultDisposition ) ) - return "!" + m_info.capturedExpression; - else - return m_info.capturedExpression; - } - std::string AssertionResult::getExpressionInMacro() const { - if( m_info.macroName.empty() ) - return m_info.capturedExpression; - else - return m_info.macroName + "( " + m_info.capturedExpression + " )"; - } - - bool AssertionResult::hasExpandedExpression() const { - return hasExpression() && getExpandedExpression() != getExpression(); - } - - std::string AssertionResult::getExpandedExpression() const { - return m_resultData.reconstructedExpression; - } - - std::string AssertionResult::getMessage() const { - return m_resultData.message; - } - SourceLineInfo AssertionResult::getSourceInfo() const { - return m_info.lineInfo; - } - - std::string AssertionResult::getTestMacroName() const { - return m_info.macroName; - } - -} // end namespace Catch - -// #included from: catch_test_case_info.hpp -#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED - -namespace Catch { - - inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { - if( startsWith( tag, "." ) || - tag == "hide" || - tag == "!hide" ) - return TestCaseInfo::IsHidden; - else if( tag == "!throws" ) - return TestCaseInfo::Throws; - else if( tag == "!shouldfail" ) - return TestCaseInfo::ShouldFail; - else if( tag == "!mayfail" ) - return TestCaseInfo::MayFail; - else - return TestCaseInfo::None; - } - inline bool isReservedTag( std::string const& tag ) { - return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !isalnum( tag[0] ); - } - inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { - if( isReservedTag( tag ) ) { - { - Colour colourGuard( Colour::Red ); - Catch::cerr() - << "Tag name [" << tag << "] not allowed.\n" - << "Tag names starting with non alpha-numeric characters are reserved\n"; - } - { - Colour colourGuard( Colour::FileName ); - Catch::cerr() << _lineInfo << std::endl; - } - exit(1); - } - } - - TestCase makeTestCase( ITestCase* _testCase, - std::string const& _className, - std::string const& _name, - std::string const& _descOrTags, - SourceLineInfo const& _lineInfo ) - { - bool isHidden( startsWith( _name, "./" ) ); // Legacy support - - // Parse out tags - std::set tags; - std::string desc, tag; - bool inTag = false; - for( std::size_t i = 0; i < _descOrTags.size(); ++i ) { - char c = _descOrTags[i]; - if( !inTag ) { - if( c == '[' ) - inTag = true; - else - desc += c; - } - else { - if( c == ']' ) { - TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); - if( prop == TestCaseInfo::IsHidden ) - isHidden = true; - else if( prop == TestCaseInfo::None ) - enforceNotReservedTag( tag, _lineInfo ); - - tags.insert( tag ); - tag.clear(); - inTag = false; - } - else - tag += c; - } - } - if( isHidden ) { - tags.insert( "hide" ); - tags.insert( "." ); - } - - TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); - return TestCase( _testCase, info ); - } - - TestCaseInfo::TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::set const& _tags, - SourceLineInfo const& _lineInfo ) - : name( _name ), - className( _className ), - description( _description ), - tags( _tags ), - lineInfo( _lineInfo ), - properties( None ) - { - std::ostringstream oss; - for( std::set::const_iterator it = _tags.begin(), itEnd = _tags.end(); it != itEnd; ++it ) { - oss << "[" << *it << "]"; - std::string lcaseTag = toLower( *it ); - properties = static_cast( properties | parseSpecialTag( lcaseTag ) ); - lcaseTags.insert( lcaseTag ); - } - tagsAsString = oss.str(); - } - - TestCaseInfo::TestCaseInfo( TestCaseInfo const& other ) - : name( other.name ), - className( other.className ), - description( other.description ), - tags( other.tags ), - lcaseTags( other.lcaseTags ), - tagsAsString( other.tagsAsString ), - lineInfo( other.lineInfo ), - properties( other.properties ) - {} - - bool TestCaseInfo::isHidden() const { - return ( properties & IsHidden ) != 0; - } - bool TestCaseInfo::throws() const { - return ( properties & Throws ) != 0; - } - bool TestCaseInfo::okToFail() const { - return ( properties & (ShouldFail | MayFail ) ) != 0; - } - bool TestCaseInfo::expectedToFail() const { - return ( properties & (ShouldFail ) ) != 0; - } - - TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} - - TestCase::TestCase( TestCase const& other ) - : TestCaseInfo( other ), - test( other.test ) - {} - - TestCase TestCase::withName( std::string const& _newName ) const { - TestCase other( *this ); - other.name = _newName; - return other; - } - - void TestCase::swap( TestCase& other ) { - test.swap( other.test ); - name.swap( other.name ); - className.swap( other.className ); - description.swap( other.description ); - tags.swap( other.tags ); - lcaseTags.swap( other.lcaseTags ); - tagsAsString.swap( other.tagsAsString ); - std::swap( TestCaseInfo::properties, static_cast( other ).properties ); - std::swap( lineInfo, other.lineInfo ); - } - - void TestCase::invoke() const { - test->invoke(); - } - - bool TestCase::operator == ( TestCase const& other ) const { - return test.get() == other.test.get() && - name == other.name && - className == other.className; - } - - bool TestCase::operator < ( TestCase const& other ) const { - return name < other.name; - } - TestCase& TestCase::operator = ( TestCase const& other ) { - TestCase temp( other ); - swap( temp ); - return *this; - } - - TestCaseInfo const& TestCase::getTestCaseInfo() const - { - return *this; - } - -} // end namespace Catch - -// #included from: catch_version.hpp -#define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED - -namespace Catch { - - Version::Version - ( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - std::string const& _branchName, - unsigned int _buildNumber ) - : majorVersion( _majorVersion ), - minorVersion( _minorVersion ), - patchNumber( _patchNumber ), - branchName( _branchName ), - buildNumber( _buildNumber ) - {} - - std::ostream& operator << ( std::ostream& os, Version const& version ) { - os << version.majorVersion << "." - << version.minorVersion << "." - << version.patchNumber; - - if( !version.branchName.empty() ) { - os << "-" << version.branchName - << "." << version.buildNumber; - } - return os; - } - - Version libraryVersion( 1, 2, 1, "", 0 ); - -} - -// #included from: catch_message.hpp -#define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED - -namespace Catch { - - MessageInfo::MessageInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ) - : macroName( _macroName ), - lineInfo( _lineInfo ), - type( _type ), - sequence( ++globalCount ) - {} - - // This may need protecting if threading support is added - unsigned int MessageInfo::globalCount = 0; - - //////////////////////////////////////////////////////////////////////////// - - ScopedMessage::ScopedMessage( MessageBuilder const& builder ) - : m_info( builder.m_info ) - { - m_info.message = builder.m_stream.str(); - getResultCapture().pushScopedMessage( m_info ); - } - ScopedMessage::ScopedMessage( ScopedMessage const& other ) - : m_info( other.m_info ) - {} - - ScopedMessage::~ScopedMessage() { - getResultCapture().popScopedMessage( m_info ); - } - -} // end namespace Catch - -// #included from: catch_legacy_reporter_adapter.hpp -#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED - -// #included from: catch_legacy_reporter_adapter.h -#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED - -namespace Catch -{ - // Deprecated - struct IReporter : IShared { - virtual ~IReporter(); - - virtual bool shouldRedirectStdout() const = 0; - - virtual void StartTesting() = 0; - virtual void EndTesting( Totals const& totals ) = 0; - virtual void StartGroup( std::string const& groupName ) = 0; - virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0; - virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0; - virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0; - virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0; - virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0; - virtual void NoAssertionsInSection( std::string const& sectionName ) = 0; - virtual void NoAssertionsInTestCase( std::string const& testName ) = 0; - virtual void Aborted() = 0; - virtual void Result( AssertionResult const& result ) = 0; - }; - - class LegacyReporterAdapter : public SharedImpl - { - public: - LegacyReporterAdapter( Ptr const& legacyReporter ); - virtual ~LegacyReporterAdapter(); - - virtual ReporterPreferences getPreferences() const; - virtual void noMatchingTestCases( std::string const& ); - virtual void testRunStarting( TestRunInfo const& ); - virtual void testGroupStarting( GroupInfo const& groupInfo ); - virtual void testCaseStarting( TestCaseInfo const& testInfo ); - virtual void sectionStarting( SectionInfo const& sectionInfo ); - virtual void assertionStarting( AssertionInfo const& ); - virtual bool assertionEnded( AssertionStats const& assertionStats ); - virtual void sectionEnded( SectionStats const& sectionStats ); - virtual void testCaseEnded( TestCaseStats const& testCaseStats ); - virtual void testGroupEnded( TestGroupStats const& testGroupStats ); - virtual void testRunEnded( TestRunStats const& testRunStats ); - virtual void skipTest( TestCaseInfo const& ); - - private: - Ptr m_legacyReporter; - }; -} - -namespace Catch -{ - LegacyReporterAdapter::LegacyReporterAdapter( Ptr const& legacyReporter ) - : m_legacyReporter( legacyReporter ) - {} - LegacyReporterAdapter::~LegacyReporterAdapter() {} - - ReporterPreferences LegacyReporterAdapter::getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout(); - return prefs; - } - - void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {} - void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) { - m_legacyReporter->StartTesting(); - } - void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) { - m_legacyReporter->StartGroup( groupInfo.name ); - } - void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) { - m_legacyReporter->StartTestCase( testInfo ); - } - void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) { - m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); - } - void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) { - // Not on legacy interface - } - - bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { - if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { - for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); - it != itEnd; - ++it ) { - if( it->type == ResultWas::Info ) { - ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal ); - rb << it->message; - rb.setResultType( ResultWas::Info ); - AssertionResult result = rb.build(); - m_legacyReporter->Result( result ); - } - } - } - m_legacyReporter->Result( assertionStats.assertionResult ); - return true; - } - void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) { - if( sectionStats.missingAssertions ) - m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); - m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); - } - void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) { - m_legacyReporter->EndTestCase - ( testCaseStats.testInfo, - testCaseStats.totals, - testCaseStats.stdOut, - testCaseStats.stdErr ); - } - void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) { - if( testGroupStats.aborting ) - m_legacyReporter->Aborted(); - m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals ); - } - void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) { - m_legacyReporter->EndTesting( testRunStats.totals ); - } - void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) { - } -} - -// #included from: catch_timer.hpp - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wc++11-long-long" -#endif - -#ifdef CATCH_PLATFORM_WINDOWS -#include -#else -#include -#endif - -namespace Catch { - - namespace { -#ifdef CATCH_PLATFORM_WINDOWS - uint64_t getCurrentTicks() { - static uint64_t hz=0, hzo=0; - if (!hz) { - QueryPerformanceFrequency( reinterpret_cast( &hz ) ); - QueryPerformanceCounter( reinterpret_cast( &hzo ) ); - } - uint64_t t; - QueryPerformanceCounter( reinterpret_cast( &t ) ); - return ((t-hzo)*1000000)/hz; - } -#else - uint64_t getCurrentTicks() { - timeval t; - gettimeofday(&t,NULL); - return static_cast( t.tv_sec ) * 1000000ull + static_cast( t.tv_usec ); - } -#endif - } - - void Timer::start() { - m_ticks = getCurrentTicks(); - } - unsigned int Timer::getElapsedMicroseconds() const { - return static_cast(getCurrentTicks() - m_ticks); - } - unsigned int Timer::getElapsedMilliseconds() const { - return static_cast(getElapsedMicroseconds()/1000); - } - double Timer::getElapsedSeconds() const { - return getElapsedMicroseconds()/1000000.0; - } - -} // namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -// #included from: catch_common.hpp -#define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED - -namespace Catch { - - bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix; - } - bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix; - } - bool contains( std::string const& s, std::string const& infix ) { - return s.find( infix ) != std::string::npos; - } - void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), ::tolower ); - } - std::string toLower( std::string const& s ) { - std::string lc = s; - toLowerInPlace( lc ); - return lc; - } - std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; - std::string::size_type start = str.find_first_not_of( whitespaceChars ); - std::string::size_type end = str.find_last_not_of( whitespaceChars ); - - return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; - } - - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { - bool replaced = false; - std::size_t i = str.find( replaceThis ); - while( i != std::string::npos ) { - replaced = true; - str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); - if( i < str.size()-withThis.size() ) - i = str.find( replaceThis, i+withThis.size() ); - else - i = std::string::npos; - } - return replaced; - } - - pluralise::pluralise( std::size_t count, std::string const& label ) - : m_count( count ), - m_label( label ) - {} - - std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << " " << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << "s"; - return os; - } - - SourceLineInfo::SourceLineInfo() : line( 0 ){} - SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) - : file( _file ), - line( _line ) - {} - SourceLineInfo::SourceLineInfo( SourceLineInfo const& other ) - : file( other.file ), - line( other.line ) - {} - bool SourceLineInfo::empty() const { - return file.empty(); - } - bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const { - return line == other.line && file == other.file; - } - bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const { - return line < other.line || ( line == other.line && file < other.file ); - } - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { -#ifndef __GNUG__ - os << info.file << "(" << info.line << ")"; -#else - os << info.file << ":" << info.line; -#endif - return os; - } - - void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) { - std::ostringstream oss; - oss << locationInfo << ": Internal Catch error: '" << message << "'"; - if( alwaysTrue() ) - throw std::logic_error( oss.str() ); - } -} - -// #included from: catch_section.hpp -#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED - -namespace Catch { - - SectionInfo::SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description ) - : name( _name ), - description( _description ), - lineInfo( _lineInfo ) - {} - - Section::Section( SectionInfo const& info ) - : m_info( info ), - m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) - { - m_timer.start(); - } - - Section::~Section() { - if( m_sectionIncluded ) - getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() ); - } - - // This indicates whether the section should be executed or not - Section::operator bool() const { - return m_sectionIncluded; - } - -} // end namespace Catch - -// #included from: catch_debugger.hpp -#define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED - -#include - -#ifdef CATCH_PLATFORM_MAC - - #include - #include - #include - #include - #include - - namespace Catch{ - - // The following function is taken directly from the following technical note: - // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html - - // Returns true if the current process is being debugged (either - // running under the debugger or has a debugger attached post facto). - bool isDebuggerActive(){ - - int mib[4]; - struct kinfo_proc info; - size_t size; - - // Initialize the flags so that, if sysctl fails for some bizarre - // reason, we get a predictable result. - - info.kp_proc.p_flag = 0; - - // Initialize mib, which tells sysctl the info we want, in this case - // we're looking for information about a specific process ID. - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = getpid(); - - // Call sysctl. - - size = sizeof(info); - if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) != 0 ) { - Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; - return false; - } - - // We're being debugged if the P_TRACED flag is set. - - return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); - } - } // namespace Catch - -#elif defined(_MSC_VER) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#else - namespace Catch { - inline bool isDebuggerActive() { return false; } - } -#endif // Platform - -#ifdef CATCH_PLATFORM_WINDOWS - extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* ); - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - ::OutputDebugStringA( text.c_str() ); - } - } -#else - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - // !TBD: Need a version for Mac/ XCode and other IDEs - Catch::cout() << text; - } - } -#endif // Platform - -// #included from: catch_tostring.hpp -#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED - -namespace Catch { - -namespace Detail { - - std::string unprintableString = "{?}"; - - namespace { - struct Endianness { - enum Arch { Big, Little }; - - static Arch which() { - union _{ - int asInt; - char asChar[sizeof (int)]; - } u; - - u.asInt = 1; - return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; - } - }; - } - - std::string rawMemoryToString( const void *object, std::size_t size ) - { - // Reverse order for little endian architectures - int i = 0, end = static_cast( size ), inc = 1; - if( Endianness::which() == Endianness::Little ) { - i = end-1; - end = inc = -1; - } - - unsigned char const *bytes = static_cast(object); - std::ostringstream os; - os << "0x" << std::setfill('0') << std::hex; - for( ; i != end; i += inc ) - os << std::setw(2) << static_cast(bytes[i]); - return os.str(); - } -} - -std::string toString( std::string const& value ) { - std::string s = value; - if( getCurrentContext().getConfig()->showInvisibles() ) { - for(size_t i = 0; i < s.size(); ++i ) { - std::string subs; - switch( s[i] ) { - case '\n': subs = "\\n"; break; - case '\t': subs = "\\t"; break; - default: break; - } - if( !subs.empty() ) { - s = s.substr( 0, i ) + subs + s.substr( i+1 ); - ++i; - } - } - } - return "\"" + s + "\""; -} -std::string toString( std::wstring const& value ) { - - std::string s; - s.reserve( value.size() ); - for(size_t i = 0; i < value.size(); ++i ) - s += value[i] <= 0xff ? static_cast( value[i] ) : '?'; - return Catch::toString( s ); -} - -std::string toString( const char* const value ) { - return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" ); -} - -std::string toString( char* const value ) { - return Catch::toString( static_cast( value ) ); -} - -std::string toString( const wchar_t* const value ) -{ - return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); -} - -std::string toString( wchar_t* const value ) -{ - return Catch::toString( static_cast( value ) ); -} - -std::string toString( int value ) { - std::ostringstream oss; - oss << value; - if( value >= 255 ) - oss << " (0x" << std::hex << value << ")"; - return oss.str(); -} - -std::string toString( unsigned long value ) { - std::ostringstream oss; - oss << value; - if( value >= 255 ) - oss << " (0x" << std::hex << value << ")"; - return oss.str(); -} - -std::string toString( unsigned int value ) { - return Catch::toString( static_cast( value ) ); -} - -template -std::string fpToString( T value, int precision ) { - std::ostringstream oss; - oss << std::setprecision( precision ) - << std::fixed - << value; - std::string d = oss.str(); - std::size_t i = d.find_last_not_of( '0' ); - if( i != std::string::npos && i != d.size()-1 ) { - if( d[i] == '.' ) - i++; - d = d.substr( 0, i+1 ); - } - return d; -} - -std::string toString( const double value ) { - return fpToString( value, 10 ); -} -std::string toString( const float value ) { - return fpToString( value, 5 ) + "f"; -} - -std::string toString( bool value ) { - return value ? "true" : "false"; -} - -std::string toString( char value ) { - return value < ' ' - ? toString( static_cast( value ) ) - : Detail::makeString( value ); -} - -std::string toString( signed char value ) { - return toString( static_cast( value ) ); -} - -std::string toString( unsigned char value ) { - return toString( static_cast( value ) ); -} - -#ifdef CATCH_CONFIG_CPP11_NULLPTR -std::string toString( std::nullptr_t ) { - return "nullptr"; -} -#endif - -#ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ) { - if( !nsstring ) - return "nil"; - return "@" + toString([nsstring UTF8String]); - } - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) { - if( !nsstring ) - return "nil"; - return "@" + toString([nsstring UTF8String]); - } - std::string toString( NSObject* const& nsObject ) { - return toString( [nsObject description] ); - } -#endif - -} // end namespace Catch - -// #included from: catch_result_builder.hpp -#define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED - -namespace Catch { - - ResultBuilder::ResultBuilder( char const* macroName, - SourceLineInfo const& lineInfo, - char const* capturedExpression, - ResultDisposition::Flags resultDisposition ) - : m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition ), - m_shouldDebugBreak( false ), - m_shouldThrow( false ) - {} - - ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) { - m_data.resultType = result; - return *this; - } - ResultBuilder& ResultBuilder::setResultType( bool result ) { - m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; - return *this; - } - ResultBuilder& ResultBuilder::setLhs( std::string const& lhs ) { - m_exprComponents.lhs = lhs; - return *this; - } - ResultBuilder& ResultBuilder::setRhs( std::string const& rhs ) { - m_exprComponents.rhs = rhs; - return *this; - } - ResultBuilder& ResultBuilder::setOp( std::string const& op ) { - m_exprComponents.op = op; - return *this; - } - - void ResultBuilder::endExpression() { - m_exprComponents.testFalse = isFalseTest( m_assertionInfo.resultDisposition ); - captureExpression(); - } - - void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) { - m_assertionInfo.resultDisposition = resultDisposition; - m_stream.oss << Catch::translateActiveException(); - captureResult( ResultWas::ThrewException ); - } - - void ResultBuilder::captureResult( ResultWas::OfType resultType ) { - setResultType( resultType ); - captureExpression(); - } - - void ResultBuilder::captureExpression() { - AssertionResult result = build(); - getResultCapture().assertionEnded( result ); - - if( !result.isOk() ) { - if( getCurrentContext().getConfig()->shouldDebugBreak() ) - m_shouldDebugBreak = true; - if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) ) - m_shouldThrow = true; - } - } - void ResultBuilder::react() { - if( m_shouldThrow ) - throw Catch::TestFailureException(); - } - - bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; } - bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); } - - AssertionResult ResultBuilder::build() const - { - assert( m_data.resultType != ResultWas::Unknown ); - - AssertionResultData data = m_data; - - // Flip bool results if testFalse is set - if( m_exprComponents.testFalse ) { - if( data.resultType == ResultWas::Ok ) - data.resultType = ResultWas::ExpressionFailed; - else if( data.resultType == ResultWas::ExpressionFailed ) - data.resultType = ResultWas::Ok; - } - - data.message = m_stream.oss.str(); - data.reconstructedExpression = reconstructExpression(); - if( m_exprComponents.testFalse ) { - if( m_exprComponents.op == "" ) - data.reconstructedExpression = "!" + data.reconstructedExpression; - else - data.reconstructedExpression = "!(" + data.reconstructedExpression + ")"; - } - return AssertionResult( m_assertionInfo, data ); - } - std::string ResultBuilder::reconstructExpression() const { - if( m_exprComponents.op == "" ) - return m_exprComponents.lhs.empty() ? m_assertionInfo.capturedExpression : m_exprComponents.op + m_exprComponents.lhs; - else if( m_exprComponents.op == "matches" ) - return m_exprComponents.lhs + " " + m_exprComponents.rhs; - else if( m_exprComponents.op != "!" ) { - if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 40 && - m_exprComponents.lhs.find("\n") == std::string::npos && - m_exprComponents.rhs.find("\n") == std::string::npos ) - return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs; - else - return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs; - } - else - return "{can't expand - use " + m_assertionInfo.macroName + "_FALSE( " + m_assertionInfo.capturedExpression.substr(1) + " ) instead of " + m_assertionInfo.macroName + "( " + m_assertionInfo.capturedExpression + " ) for better diagnostics}"; - } - -} // end namespace Catch - -// #included from: catch_tag_alias_registry.hpp -#define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED - -// #included from: catch_tag_alias_registry.h -#define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED - -#include - -namespace Catch { - - class TagAliasRegistry : public ITagAliasRegistry { - public: - virtual ~TagAliasRegistry(); - virtual Option find( std::string const& alias ) const; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const; - void add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - static TagAliasRegistry& get(); - - private: - std::map m_registry; - }; - -} // end namespace Catch - -#include -#include - -namespace Catch { - - TagAliasRegistry::~TagAliasRegistry() {} - - Option TagAliasRegistry::find( std::string const& alias ) const { - std::map::const_iterator it = m_registry.find( alias ); - if( it != m_registry.end() ) - return it->second; - else - return Option(); - } - - std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { - std::string expandedTestSpec = unexpandedTestSpec; - for( std::map::const_iterator it = m_registry.begin(), itEnd = m_registry.end(); - it != itEnd; - ++it ) { - std::size_t pos = expandedTestSpec.find( it->first ); - if( pos != std::string::npos ) { - expandedTestSpec = expandedTestSpec.substr( 0, pos ) + - it->second.tag + - expandedTestSpec.substr( pos + it->first.size() ); - } - } - return expandedTestSpec; - } - - void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { - - if( !startsWith( alias, "[@" ) || !endsWith( alias, "]" ) ) { - std::ostringstream oss; - oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo; - throw std::domain_error( oss.str().c_str() ); - } - if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) { - std::ostringstream oss; - oss << "error: tag alias, \"" << alias << "\" already registered.\n" - << "\tFirst seen at " << find(alias)->lineInfo << "\n" - << "\tRedefined at " << lineInfo; - throw std::domain_error( oss.str().c_str() ); - } - } - - TagAliasRegistry& TagAliasRegistry::get() { - static TagAliasRegistry instance; - return instance; - - } - - ITagAliasRegistry::~ITagAliasRegistry() {} - ITagAliasRegistry const& ITagAliasRegistry::get() { return TagAliasRegistry::get(); } - - RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { - try { - TagAliasRegistry::get().add( alias, tag, lineInfo ); - } - catch( std::exception& ex ) { - Colour colourGuard( Colour::Red ); - Catch::cerr() << ex.what() << std::endl; - exit(1); - } - } - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_xml.hpp -#define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED - -// #included from: catch_reporter_bases.hpp -#define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED - -#include - -namespace Catch { - - struct StreamingReporterBase : SharedImpl { - - StreamingReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - {} - - virtual ~StreamingReporterBase(); - - virtual void noMatchingTestCases( std::string const& ) {} - - virtual void testRunStarting( TestRunInfo const& _testRunInfo ) { - currentTestRunInfo = _testRunInfo; - } - virtual void testGroupStarting( GroupInfo const& _groupInfo ) { - currentGroupInfo = _groupInfo; - } - - virtual void testCaseStarting( TestCaseInfo const& _testInfo ) { - currentTestCaseInfo = _testInfo; - } - virtual void sectionStarting( SectionInfo const& _sectionInfo ) { - m_sectionStack.push_back( _sectionInfo ); - } - - virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) { - m_sectionStack.pop_back(); - } - virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) { - currentTestCaseInfo.reset(); - } - virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) { - currentGroupInfo.reset(); - } - virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) { - currentTestCaseInfo.reset(); - currentGroupInfo.reset(); - currentTestRunInfo.reset(); - } - - virtual void skipTest( TestCaseInfo const& ) { - // Don't do anything with this by default. - // It can optionally be overridden in the derived class. - } - - Ptr m_config; - std::ostream& stream; - - LazyStat currentTestRunInfo; - LazyStat currentGroupInfo; - LazyStat currentTestCaseInfo; - - std::vector m_sectionStack; - }; - - struct CumulativeReporterBase : SharedImpl { - template - struct Node : SharedImpl<> { - explicit Node( T const& _value ) : value( _value ) {} - virtual ~Node() {} - - typedef std::vector > ChildNodes; - T value; - ChildNodes children; - }; - struct SectionNode : SharedImpl<> { - explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {} - virtual ~SectionNode(); - - bool operator == ( SectionNode const& other ) const { - return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; - } - bool operator == ( Ptr const& other ) const { - return operator==( *other ); - } - - SectionStats stats; - typedef std::vector > ChildSections; - typedef std::vector Assertions; - ChildSections childSections; - Assertions assertions; - std::string stdOut; - std::string stdErr; - }; - - struct BySectionInfo { - BySectionInfo( SectionInfo const& other ) : m_other( other ) {} - BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} - bool operator() ( Ptr const& node ) const { - return node->stats.sectionInfo.lineInfo == m_other.lineInfo; - } - private: - void operator=( BySectionInfo const& ); - SectionInfo const& m_other; - }; - - typedef Node TestCaseNode; - typedef Node TestGroupNode; - typedef Node TestRunNode; - - CumulativeReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - {} - ~CumulativeReporterBase(); - - virtual void testRunStarting( TestRunInfo const& ) {} - virtual void testGroupStarting( GroupInfo const& ) {} - - virtual void testCaseStarting( TestCaseInfo const& ) {} - - virtual void sectionStarting( SectionInfo const& sectionInfo ) { - SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); - Ptr node; - if( m_sectionStack.empty() ) { - if( !m_rootSection ) - m_rootSection = new SectionNode( incompleteStats ); - node = m_rootSection; - } - else { - SectionNode& parentNode = *m_sectionStack.back(); - SectionNode::ChildSections::const_iterator it = - std::find_if( parentNode.childSections.begin(), - parentNode.childSections.end(), - BySectionInfo( sectionInfo ) ); - if( it == parentNode.childSections.end() ) { - node = new SectionNode( incompleteStats ); - parentNode.childSections.push_back( node ); - } - else - node = *it; - } - m_sectionStack.push_back( node ); - m_deepestSection = node; - } - - virtual void assertionStarting( AssertionInfo const& ) {} - - virtual bool assertionEnded( AssertionStats const& assertionStats ) { - assert( !m_sectionStack.empty() ); - SectionNode& sectionNode = *m_sectionStack.back(); - sectionNode.assertions.push_back( assertionStats ); - return true; - } - virtual void sectionEnded( SectionStats const& sectionStats ) { - assert( !m_sectionStack.empty() ); - SectionNode& node = *m_sectionStack.back(); - node.stats = sectionStats; - m_sectionStack.pop_back(); - } - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { - Ptr node = new TestCaseNode( testCaseStats ); - assert( m_sectionStack.size() == 0 ); - node->children.push_back( m_rootSection ); - m_testCases.push_back( node ); - m_rootSection.reset(); - - assert( m_deepestSection ); - m_deepestSection->stdOut = testCaseStats.stdOut; - m_deepestSection->stdErr = testCaseStats.stdErr; - } - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { - Ptr node = new TestGroupNode( testGroupStats ); - node->children.swap( m_testCases ); - m_testGroups.push_back( node ); - } - virtual void testRunEnded( TestRunStats const& testRunStats ) { - Ptr node = new TestRunNode( testRunStats ); - node->children.swap( m_testGroups ); - m_testRuns.push_back( node ); - testRunEndedCumulative(); - } - virtual void testRunEndedCumulative() = 0; - - virtual void skipTest( TestCaseInfo const& ) {} - - Ptr m_config; - std::ostream& stream; - std::vector m_assertions; - std::vector > > m_sections; - std::vector > m_testCases; - std::vector > m_testGroups; - - std::vector > m_testRuns; - - Ptr m_rootSection; - Ptr m_deepestSection; - std::vector > m_sectionStack; - - }; - - template - char const* getLineOfChars() { - static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; - if( !*line ) { - memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); - line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; - } - return line; - } - -} // end namespace Catch - -// #included from: ../internal/catch_reporter_registrars.hpp -#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED - -namespace Catch { - - template - class LegacyReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - virtual IStreamingReporter* create( ReporterConfig const& config ) const { - return new LegacyReporterAdapter( new T( config ) ); - } - - virtual std::string getDescription() const { - return T::getDescription(); - } - }; - - public: - - LegacyReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); - } - }; - - template - class ReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - - // *** Please Note ***: - // - If you end up here looking at a compiler error because it's trying to register - // your custom reporter class be aware that the native reporter interface has changed - // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via - // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter. - // However please consider updating to the new interface as the old one is now - // deprecated and will probably be removed quite soon! - // Please contact me via github if you have any questions at all about this. - // In fact, ideally, please contact me anyway to let me know you've hit this - as I have - // no idea who is actually using custom reporters at all (possibly no-one!). - // The new interface is designed to minimise exposure to interface changes in the future. - virtual IStreamingReporter* create( ReporterConfig const& config ) const { - return new T( config ); - } - - virtual std::string getDescription() const { - return T::getDescription(); - } - }; - - public: - - ReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); - } - }; -} - -#define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \ - namespace{ Catch::LegacyReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } -#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ - namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } - -// #included from: ../internal/catch_xmlwriter.hpp -#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED - -#include -#include -#include - -namespace Catch { - - class XmlWriter { - public: - - class ScopedElement { - public: - ScopedElement( XmlWriter* writer ) - : m_writer( writer ) - {} - - ScopedElement( ScopedElement const& other ) - : m_writer( other.m_writer ){ - other.m_writer = NULL; - } - - ~ScopedElement() { - if( m_writer ) - m_writer->endElement(); - } - - ScopedElement& writeText( std::string const& text, bool indent = true ) { - m_writer->writeText( text, indent ); - return *this; - } - - template - ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { - m_writer->writeAttribute( name, attribute ); - return *this; - } - - private: - mutable XmlWriter* m_writer; - }; - - XmlWriter() - : m_tagIsOpen( false ), - m_needsNewline( false ), - m_os( &Catch::cout() ) - {} - - XmlWriter( std::ostream& os ) - : m_tagIsOpen( false ), - m_needsNewline( false ), - m_os( &os ) - {} - - ~XmlWriter() { - while( !m_tags.empty() ) - endElement(); - } - - XmlWriter& startElement( std::string const& name ) { - ensureTagClosed(); - newlineIfNecessary(); - stream() << m_indent << "<" << name; - m_tags.push_back( name ); - m_indent += " "; - m_tagIsOpen = true; - return *this; - } - - ScopedElement scopedElement( std::string const& name ) { - ScopedElement scoped( this ); - startElement( name ); - return scoped; - } - - XmlWriter& endElement() { - newlineIfNecessary(); - m_indent = m_indent.substr( 0, m_indent.size()-2 ); - if( m_tagIsOpen ) { - stream() << "/>\n"; - m_tagIsOpen = false; - } - else { - stream() << m_indent << "\n"; - } - m_tags.pop_back(); - return *this; - } - - XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) { - if( !name.empty() && !attribute.empty() ) { - stream() << " " << name << "=\""; - writeEncodedText( attribute ); - stream() << "\""; - } - return *this; - } - - XmlWriter& writeAttribute( std::string const& name, bool attribute ) { - stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\""; - return *this; - } - - template - XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { - if( !name.empty() ) - stream() << " " << name << "=\"" << attribute << "\""; - return *this; - } - - XmlWriter& writeText( std::string const& text, bool indent = true ) { - if( !text.empty() ){ - bool tagWasOpen = m_tagIsOpen; - ensureTagClosed(); - if( tagWasOpen && indent ) - stream() << m_indent; - writeEncodedText( text ); - m_needsNewline = true; - } - return *this; - } - - XmlWriter& writeComment( std::string const& text ) { - ensureTagClosed(); - stream() << m_indent << ""; - m_needsNewline = true; - return *this; - } - - XmlWriter& writeBlankLine() { - ensureTagClosed(); - stream() << "\n"; - return *this; - } - - void setStream( std::ostream& os ) { - m_os = &os; - } - - private: - XmlWriter( XmlWriter const& ); - void operator=( XmlWriter const& ); - - std::ostream& stream() { - return *m_os; - } - - void ensureTagClosed() { - if( m_tagIsOpen ) { - stream() << ">\n"; - m_tagIsOpen = false; - } - } - - void newlineIfNecessary() { - if( m_needsNewline ) { - stream() << "\n"; - m_needsNewline = false; - } - } - - void writeEncodedText( std::string const& text ) { - static const char* charsToEncode = "<&\""; - std::string mtext = text; - std::string::size_type pos = mtext.find_first_of( charsToEncode ); - while( pos != std::string::npos ) { - stream() << mtext.substr( 0, pos ); - - switch( mtext[pos] ) { - case '<': - stream() << "<"; - break; - case '&': - stream() << "&"; - break; - case '\"': - stream() << """; - break; - } - mtext = mtext.substr( pos+1 ); - pos = mtext.find_first_of( charsToEncode ); - } - stream() << mtext; - } - - bool m_tagIsOpen; - bool m_needsNewline; - std::vector m_tags; - std::string m_indent; - std::ostream* m_os; - }; - -} -namespace Catch { - class XmlReporter : public StreamingReporterBase { - public: - XmlReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ), - m_sectionDepth( 0 ) - {} - - virtual ~XmlReporter(); - - static std::string getDescription() { - return "Reports test results as an XML document"; - } - - public: // StreamingReporterBase - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = true; - return prefs; - } - - virtual void noMatchingTestCases( std::string const& s ) { - StreamingReporterBase::noMatchingTestCases( s ); - } - - virtual void testRunStarting( TestRunInfo const& testInfo ) { - StreamingReporterBase::testRunStarting( testInfo ); - m_xml.setStream( stream ); - m_xml.startElement( "Catch" ); - if( !m_config->name().empty() ) - m_xml.writeAttribute( "name", m_config->name() ); - } - - virtual void testGroupStarting( GroupInfo const& groupInfo ) { - StreamingReporterBase::testGroupStarting( groupInfo ); - m_xml.startElement( "Group" ) - .writeAttribute( "name", groupInfo.name ); - } - - virtual void testCaseStarting( TestCaseInfo const& testInfo ) { - StreamingReporterBase::testCaseStarting(testInfo); - m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); - - if ( m_config->showDurations() == ShowDurations::Always ) - m_testCaseTimer.start(); - } - - virtual void sectionStarting( SectionInfo const& sectionInfo ) { - StreamingReporterBase::sectionStarting( sectionInfo ); - if( m_sectionDepth++ > 0 ) { - m_xml.startElement( "Section" ) - .writeAttribute( "name", trim( sectionInfo.name ) ) - .writeAttribute( "description", sectionInfo.description ); - } - } - - virtual void assertionStarting( AssertionInfo const& ) { } - - virtual bool assertionEnded( AssertionStats const& assertionStats ) { - const AssertionResult& assertionResult = assertionStats.assertionResult; - - // Print any info messages in tags. - if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { - for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); - it != itEnd; - ++it ) { - if( it->type == ResultWas::Info ) { - m_xml.scopedElement( "Info" ) - .writeText( it->message ); - } else if ( it->type == ResultWas::Warning ) { - m_xml.scopedElement( "Warning" ) - .writeText( it->message ); - } - } - } - - // Drop out if result was successful but we're not printing them. - if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) ) - return true; - - // Print the expression if there is one. - if( assertionResult.hasExpression() ) { - m_xml.startElement( "Expression" ) - .writeAttribute( "success", assertionResult.succeeded() ) - .writeAttribute( "type", assertionResult.getTestMacroName() ) - .writeAttribute( "filename", assertionResult.getSourceInfo().file ) - .writeAttribute( "line", assertionResult.getSourceInfo().line ); - - m_xml.scopedElement( "Original" ) - .writeText( assertionResult.getExpression() ); - m_xml.scopedElement( "Expanded" ) - .writeText( assertionResult.getExpandedExpression() ); - } - - // And... Print a result applicable to each result type. - switch( assertionResult.getResultType() ) { - case ResultWas::ThrewException: - m_xml.scopedElement( "Exception" ) - .writeAttribute( "filename", assertionResult.getSourceInfo().file ) - .writeAttribute( "line", assertionResult.getSourceInfo().line ) - .writeText( assertionResult.getMessage() ); - break; - case ResultWas::FatalErrorCondition: - m_xml.scopedElement( "Fatal Error Condition" ) - .writeAttribute( "filename", assertionResult.getSourceInfo().file ) - .writeAttribute( "line", assertionResult.getSourceInfo().line ) - .writeText( assertionResult.getMessage() ); - break; - case ResultWas::Info: - m_xml.scopedElement( "Info" ) - .writeText( assertionResult.getMessage() ); - break; - case ResultWas::Warning: - // Warning will already have been written - break; - case ResultWas::ExplicitFailure: - m_xml.scopedElement( "Failure" ) - .writeText( assertionResult.getMessage() ); - break; - default: - break; - } - - if( assertionResult.hasExpression() ) - m_xml.endElement(); - - return true; - } - - virtual void sectionEnded( SectionStats const& sectionStats ) { - StreamingReporterBase::sectionEnded( sectionStats ); - if( --m_sectionDepth > 0 ) { - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); - e.writeAttribute( "successes", sectionStats.assertions.passed ); - e.writeAttribute( "failures", sectionStats.assertions.failed ); - e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); - - m_xml.endElement(); - } - } - - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { - StreamingReporterBase::testCaseEnded( testCaseStats ); - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); - e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); - - m_xml.endElement(); - } - - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { - StreamingReporterBase::testGroupEnded( testGroupStats ); - // TODO: Check testGroupStats.aborting and act accordingly. - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) - .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - virtual void testRunEnded( TestRunStats const& testRunStats ) { - StreamingReporterBase::testRunEnded( testRunStats ); - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testRunStats.totals.assertions.passed ) - .writeAttribute( "failures", testRunStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - private: - Timer m_testCaseTimer; - XmlWriter m_xml; - int m_sectionDepth; - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_junit.hpp -#define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED - -#include - -namespace Catch { - - class JunitReporter : public CumulativeReporterBase { - public: - JunitReporter( ReporterConfig const& _config ) - : CumulativeReporterBase( _config ), - xml( _config.stream() ) - {} - - ~JunitReporter(); - - static std::string getDescription() { - return "Reports test results in an XML format that looks like Ant's junitreport target"; - } - - virtual void noMatchingTestCases( std::string const& /*spec*/ ) {} - - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = true; - return prefs; - } - - virtual void testRunStarting( TestRunInfo const& runInfo ) { - CumulativeReporterBase::testRunStarting( runInfo ); - xml.startElement( "testsuites" ); - } - - virtual void testGroupStarting( GroupInfo const& groupInfo ) { - suiteTimer.start(); - stdOutForSuite.str(""); - stdErrForSuite.str(""); - unexpectedExceptions = 0; - CumulativeReporterBase::testGroupStarting( groupInfo ); - } - - virtual bool assertionEnded( AssertionStats const& assertionStats ) { - if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException ) - unexpectedExceptions++; - return CumulativeReporterBase::assertionEnded( assertionStats ); - } - - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { - stdOutForSuite << testCaseStats.stdOut; - stdErrForSuite << testCaseStats.stdErr; - CumulativeReporterBase::testCaseEnded( testCaseStats ); - } - - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { - double suiteTime = suiteTimer.getElapsedSeconds(); - CumulativeReporterBase::testGroupEnded( testGroupStats ); - writeGroup( *m_testGroups.back(), suiteTime ); - } - - virtual void testRunEndedCumulative() { - xml.endElement(); - } - - void writeGroup( TestGroupNode const& groupNode, double suiteTime ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); - TestGroupStats const& stats = groupNode.value; - xml.writeAttribute( "name", stats.groupInfo.name ); - xml.writeAttribute( "errors", unexpectedExceptions ); - xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); - xml.writeAttribute( "tests", stats.totals.assertions.total() ); - xml.writeAttribute( "hostname", "tbd" ); // !TBD - if( m_config->showDurations() == ShowDurations::Never ) - xml.writeAttribute( "time", "" ); - else - xml.writeAttribute( "time", suiteTime ); - xml.writeAttribute( "timestamp", "tbd" ); // !TBD - - // Write test cases - for( TestGroupNode::ChildNodes::const_iterator - it = groupNode.children.begin(), itEnd = groupNode.children.end(); - it != itEnd; - ++it ) - writeTestCase( **it ); - - xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false ); - xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); - } - - void writeTestCase( TestCaseNode const& testCaseNode ) { - TestCaseStats const& stats = testCaseNode.value; - - // All test cases have exactly one section - which represents the - // test case itself. That section may have 0-n nested sections - assert( testCaseNode.children.size() == 1 ); - SectionNode const& rootSection = *testCaseNode.children.front(); - - std::string className = stats.testInfo.className; - - if( className.empty() ) { - if( rootSection.childSections.empty() ) - className = "global"; - } - writeSection( className, "", rootSection ); - } - - void writeSection( std::string const& className, - std::string const& rootName, - SectionNode const& sectionNode ) { - std::string name = trim( sectionNode.stats.sectionInfo.name ); - if( !rootName.empty() ) - name = rootName + "/" + name; - - if( !sectionNode.assertions.empty() || - !sectionNode.stdOut.empty() || - !sectionNode.stdErr.empty() ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); - if( className.empty() ) { - xml.writeAttribute( "classname", name ); - xml.writeAttribute( "name", "root" ); - } - else { - xml.writeAttribute( "classname", className ); - xml.writeAttribute( "name", name ); - } - xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) ); - - writeAssertions( sectionNode ); - - if( !sectionNode.stdOut.empty() ) - xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); - if( !sectionNode.stdErr.empty() ) - xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); - } - for( SectionNode::ChildSections::const_iterator - it = sectionNode.childSections.begin(), - itEnd = sectionNode.childSections.end(); - it != itEnd; - ++it ) - if( className.empty() ) - writeSection( name, "", **it ); - else - writeSection( className, name, **it ); - } - - void writeAssertions( SectionNode const& sectionNode ) { - for( SectionNode::Assertions::const_iterator - it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end(); - it != itEnd; - ++it ) - writeAssertion( *it ); - } - void writeAssertion( AssertionStats const& stats ) { - AssertionResult const& result = stats.assertionResult; - if( !result.isOk() ) { - std::string elementName; - switch( result.getResultType() ) { - case ResultWas::ThrewException: - case ResultWas::FatalErrorCondition: - elementName = "error"; - break; - case ResultWas::ExplicitFailure: - elementName = "failure"; - break; - case ResultWas::ExpressionFailed: - elementName = "failure"; - break; - case ResultWas::DidntThrowException: - elementName = "failure"; - break; - - // We should never see these here: - case ResultWas::Info: - case ResultWas::Warning: - case ResultWas::Ok: - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - elementName = "internalError"; - break; - } - - XmlWriter::ScopedElement e = xml.scopedElement( elementName ); - - xml.writeAttribute( "message", result.getExpandedExpression() ); - xml.writeAttribute( "type", result.getTestMacroName() ); - - std::ostringstream oss; - if( !result.getMessage().empty() ) - oss << result.getMessage() << "\n"; - for( std::vector::const_iterator - it = stats.infoMessages.begin(), - itEnd = stats.infoMessages.end(); - it != itEnd; - ++it ) - if( it->type == ResultWas::Info ) - oss << it->message << "\n"; - - oss << "at " << result.getSourceInfo(); - xml.writeText( oss.str(), false ); - } - } - - XmlWriter xml; - Timer suiteTimer; - std::ostringstream stdOutForSuite; - std::ostringstream stdErrForSuite; - unsigned int unexpectedExceptions; - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_console.hpp -#define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED - -namespace Catch { - - struct ConsoleReporter : StreamingReporterBase { - ConsoleReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ), - m_headerPrinted( false ) - {} - - virtual ~ConsoleReporter(); - static std::string getDescription() { - return "Reports test results as plain lines of text"; - } - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = false; - return prefs; - } - - virtual void noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << "'" << std::endl; - } - - virtual void assertionStarting( AssertionInfo const& ) { - } - - virtual bool assertionEnded( AssertionStats const& _assertionStats ) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool printInfoMessages = true; - - // Drop out if result was successful and we're not printing those - if( !m_config->includeSuccessfulResults() && result.isOk() ) { - if( result.getResultType() != ResultWas::Warning ) - return false; - printInfoMessages = false; - } - - lazyPrint(); - - AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); - printer.print(); - stream << std::endl; - return true; - } - - virtual void sectionStarting( SectionInfo const& _sectionInfo ) { - m_headerPrinted = false; - StreamingReporterBase::sectionStarting( _sectionInfo ); - } - virtual void sectionEnded( SectionStats const& _sectionStats ) { - if( _sectionStats.missingAssertions ) { - lazyPrint(); - Colour colour( Colour::ResultError ); - if( m_sectionStack.size() > 1 ) - stream << "\nNo assertions in section"; - else - stream << "\nNo assertions in test case"; - stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; - } - if( m_headerPrinted ) { - if( m_config->showDurations() == ShowDurations::Always ) - stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl; - m_headerPrinted = false; - } - else { - if( m_config->showDurations() == ShowDurations::Always ) - stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl; - } - StreamingReporterBase::sectionEnded( _sectionStats ); - } - - virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) { - StreamingReporterBase::testCaseEnded( _testCaseStats ); - m_headerPrinted = false; - } - virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) { - if( currentGroupInfo.used ) { - printSummaryDivider(); - stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; - printTotals( _testGroupStats.totals ); - stream << "\n" << std::endl; - } - StreamingReporterBase::testGroupEnded( _testGroupStats ); - } - virtual void testRunEnded( TestRunStats const& _testRunStats ) { - printTotalsDivider( _testRunStats.totals ); - printTotals( _testRunStats.totals ); - stream << std::endl; - StreamingReporterBase::testRunEnded( _testRunStats ); - } - - private: - - class AssertionPrinter { - void operator= ( AssertionPrinter const& ); - public: - AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) - : stream( _stream ), - stats( _stats ), - result( _stats.assertionResult ), - colour( Colour::None ), - message( result.getMessage() ), - messages( _stats.infoMessages ), - printInfoMessages( _printInfoMessages ) - { - switch( result.getResultType() ) { - case ResultWas::Ok: - colour = Colour::Success; - passOrFail = "PASSED"; - //if( result.hasMessage() ) - if( _stats.infoMessages.size() == 1 ) - messageLabel = "with message"; - if( _stats.infoMessages.size() > 1 ) - messageLabel = "with messages"; - break; - case ResultWas::ExpressionFailed: - if( result.isOk() ) { - colour = Colour::Success; - passOrFail = "FAILED - but was ok"; - } - else { - colour = Colour::Error; - passOrFail = "FAILED"; - } - if( _stats.infoMessages.size() == 1 ) - messageLabel = "with message"; - if( _stats.infoMessages.size() > 1 ) - messageLabel = "with messages"; - break; - case ResultWas::ThrewException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to unexpected exception with message"; - break; - case ResultWas::FatalErrorCondition: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to a fatal error condition"; - break; - case ResultWas::DidntThrowException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "because no exception was thrown where one was expected"; - break; - case ResultWas::Info: - messageLabel = "info"; - break; - case ResultWas::Warning: - messageLabel = "warning"; - break; - case ResultWas::ExplicitFailure: - passOrFail = "FAILED"; - colour = Colour::Error; - if( _stats.infoMessages.size() == 1 ) - messageLabel = "explicitly with message"; - if( _stats.infoMessages.size() > 1 ) - messageLabel = "explicitly with messages"; - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - passOrFail = "** internal error **"; - colour = Colour::Error; - break; - } - } - - void print() const { - printSourceInfo(); - if( stats.totals.assertions.total() > 0 ) { - if( result.isOk() ) - stream << "\n"; - printResultType(); - printOriginalExpression(); - printReconstructedExpression(); - } - else { - stream << "\n"; - } - printMessage(); - } - - private: - void printResultType() const { - if( !passOrFail.empty() ) { - Colour colourGuard( colour ); - stream << passOrFail << ":\n"; - } - } - void printOriginalExpression() const { - if( result.hasExpression() ) { - Colour colourGuard( Colour::OriginalExpression ); - stream << " "; - stream << result.getExpressionInMacro(); - stream << "\n"; - } - } - void printReconstructedExpression() const { - if( result.hasExpandedExpression() ) { - stream << "with expansion:\n"; - Colour colourGuard( Colour::ReconstructedExpression ); - stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n"; - } - } - void printMessage() const { - if( !messageLabel.empty() ) - stream << messageLabel << ":" << "\n"; - for( std::vector::const_iterator it = messages.begin(), itEnd = messages.end(); - it != itEnd; - ++it ) { - // If this assertion is a warning ignore any INFO messages - if( printInfoMessages || it->type != ResultWas::Info ) - stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n"; - } - } - void printSourceInfo() const { - Colour colourGuard( Colour::FileName ); - stream << result.getSourceInfo() << ": "; - } - - std::ostream& stream; - AssertionStats const& stats; - AssertionResult const& result; - Colour::Code colour; - std::string passOrFail; - std::string messageLabel; - std::string message; - std::vector messages; - bool printInfoMessages; - }; - - void lazyPrint() { - - if( !currentTestRunInfo.used ) - lazyPrintRunInfo(); - if( !currentGroupInfo.used ) - lazyPrintGroupInfo(); - - if( !m_headerPrinted ) { - printTestCaseAndSectionHeader(); - m_headerPrinted = true; - } - } - void lazyPrintRunInfo() { - stream << "\n" << getLineOfChars<'~'>() << "\n"; - Colour colour( Colour::SecondaryText ); - stream << currentTestRunInfo->name - << " is a Catch v" << libraryVersion << " host application.\n" - << "Run with -? for options\n\n"; - - if( m_config->rngSeed() != 0 ) - stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; - - currentTestRunInfo.used = true; - } - void lazyPrintGroupInfo() { - if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) { - printClosedHeader( "Group: " + currentGroupInfo->name ); - currentGroupInfo.used = true; - } - } - void printTestCaseAndSectionHeader() { - assert( !m_sectionStack.empty() ); - printOpenHeader( currentTestCaseInfo->name ); - - if( m_sectionStack.size() > 1 ) { - Colour colourGuard( Colour::Headers ); - - std::vector::const_iterator - it = m_sectionStack.begin()+1, // Skip first section (test case) - itEnd = m_sectionStack.end(); - for( ; it != itEnd; ++it ) - printHeaderString( it->name, 2 ); - } - - SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; - - if( !lineInfo.empty() ){ - stream << getLineOfChars<'-'>() << "\n"; - Colour colourGuard( Colour::FileName ); - stream << lineInfo << "\n"; - } - stream << getLineOfChars<'.'>() << "\n" << std::endl; - } - - void printClosedHeader( std::string const& _name ) { - printOpenHeader( _name ); - stream << getLineOfChars<'.'>() << "\n"; - } - void printOpenHeader( std::string const& _name ) { - stream << getLineOfChars<'-'>() << "\n"; - { - Colour colourGuard( Colour::Headers ); - printHeaderString( _name ); - } - } - - // if string has a : in first line will set indent to follow it on - // subsequent lines - void printHeaderString( std::string const& _string, std::size_t indent = 0 ) { - std::size_t i = _string.find( ": " ); - if( i != std::string::npos ) - i+=2; - else - i = 0; - stream << Text( _string, TextAttributes() - .setIndent( indent+i) - .setInitialIndent( indent ) ) << "\n"; - } - - struct SummaryColumn { - - SummaryColumn( std::string const& _label, Colour::Code _colour ) - : label( _label ), - colour( _colour ) - {} - SummaryColumn addRow( std::size_t count ) { - std::ostringstream oss; - oss << count; - std::string row = oss.str(); - for( std::vector::iterator it = rows.begin(); it != rows.end(); ++it ) { - while( it->size() < row.size() ) - *it = " " + *it; - while( it->size() > row.size() ) - row = " " + row; - } - rows.push_back( row ); - return *this; - } - - std::string label; - Colour::Code colour; - std::vector rows; - - }; - - void printTotals( Totals const& totals ) { - if( totals.testCases.total() == 0 ) { - stream << Colour( Colour::Warning ) << "No tests ran\n"; - } - else if( totals.assertions.total() > 0 && totals.assertions.allPassed() ) { - stream << Colour( Colour::ResultSuccess ) << "All tests passed"; - stream << " (" - << pluralise( totals.assertions.passed, "assertion" ) << " in " - << pluralise( totals.testCases.passed, "test case" ) << ")" - << "\n"; - } - else { - - std::vector columns; - columns.push_back( SummaryColumn( "", Colour::None ) - .addRow( totals.testCases.total() ) - .addRow( totals.assertions.total() ) ); - columns.push_back( SummaryColumn( "passed", Colour::Success ) - .addRow( totals.testCases.passed ) - .addRow( totals.assertions.passed ) ); - columns.push_back( SummaryColumn( "failed", Colour::ResultError ) - .addRow( totals.testCases.failed ) - .addRow( totals.assertions.failed ) ); - columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure ) - .addRow( totals.testCases.failedButOk ) - .addRow( totals.assertions.failedButOk ) ); - - printSummaryRow( "test cases", columns, 0 ); - printSummaryRow( "assertions", columns, 1 ); - } - } - void printSummaryRow( std::string const& label, std::vector const& cols, std::size_t row ) { - for( std::vector::const_iterator it = cols.begin(); it != cols.end(); ++it ) { - std::string value = it->rows[row]; - if( it->label.empty() ) { - stream << label << ": "; - if( value != "0" ) - stream << value; - else - stream << Colour( Colour::Warning ) << "- none -"; - } - else if( value != "0" ) { - stream << Colour( Colour::LightGrey ) << " | "; - stream << Colour( it->colour ) - << value << " " << it->label; - } - } - stream << "\n"; - } - - static std::size_t makeRatio( std::size_t number, std::size_t total ) { - std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; - return ( ratio == 0 && number > 0 ) ? 1 : ratio; - } - static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { - if( i > j && i > k ) - return i; - else if( j > k ) - return j; - else - return k; - } - - void printTotalsDivider( Totals const& totals ) { - if( totals.testCases.total() > 0 ) { - std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() ); - std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() ); - std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() ); - while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 ) - findMax( failedRatio, failedButOkRatio, passedRatio )++; - while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 ) - findMax( failedRatio, failedButOkRatio, passedRatio )--; - - stream << Colour( Colour::Error ) << std::string( failedRatio, '=' ); - stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' ); - if( totals.testCases.allPassed() ) - stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' ); - else - stream << Colour( Colour::Success ) << std::string( passedRatio, '=' ); - } - else { - stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); - } - stream << "\n"; - } - void printSummaryDivider() { - stream << getLineOfChars<'-'>() << "\n"; - } - - private: - bool m_headerPrinted; - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter ) - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_compact.hpp -#define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED - -namespace Catch { - - struct CompactReporter : StreamingReporterBase { - - CompactReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ) - {} - - virtual ~CompactReporter(); - - static std::string getDescription() { - return "Reports test results on a single line, suitable for IDEs"; - } - - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = false; - return prefs; - } - - virtual void noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << "'" << std::endl; - } - - virtual void assertionStarting( AssertionInfo const& ) { - } - - virtual bool assertionEnded( AssertionStats const& _assertionStats ) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool printInfoMessages = true; - - // Drop out if result was successful and we're not printing those - if( !m_config->includeSuccessfulResults() && result.isOk() ) { - if( result.getResultType() != ResultWas::Warning ) - return false; - printInfoMessages = false; - } - - AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); - printer.print(); - - stream << std::endl; - return true; - } - - virtual void testRunEnded( TestRunStats const& _testRunStats ) { - printTotals( _testRunStats.totals ); - stream << "\n" << std::endl; - StreamingReporterBase::testRunEnded( _testRunStats ); - } - - private: - class AssertionPrinter { - void operator= ( AssertionPrinter const& ); - public: - AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) - : stream( _stream ) - , stats( _stats ) - , result( _stats.assertionResult ) - , messages( _stats.infoMessages ) - , itMessage( _stats.infoMessages.begin() ) - , printInfoMessages( _printInfoMessages ) - {} - - void print() { - printSourceInfo(); - - itMessage = messages.begin(); - - switch( result.getResultType() ) { - case ResultWas::Ok: - printResultType( Colour::ResultSuccess, passedString() ); - printOriginalExpression(); - printReconstructedExpression(); - if ( ! result.hasExpression() ) - printRemainingMessages( Colour::None ); - else - printRemainingMessages(); - break; - case ResultWas::ExpressionFailed: - if( result.isOk() ) - printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) ); - else - printResultType( Colour::Error, failedString() ); - printOriginalExpression(); - printReconstructedExpression(); - printRemainingMessages(); - break; - case ResultWas::ThrewException: - printResultType( Colour::Error, failedString() ); - printIssue( "unexpected exception with message:" ); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::FatalErrorCondition: - printResultType( Colour::Error, failedString() ); - printIssue( "fatal error condition with message:" ); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::DidntThrowException: - printResultType( Colour::Error, failedString() ); - printIssue( "expected exception, got none" ); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::Info: - printResultType( Colour::None, "info" ); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::Warning: - printResultType( Colour::None, "warning" ); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::ExplicitFailure: - printResultType( Colour::Error, failedString() ); - printIssue( "explicitly" ); - printRemainingMessages( Colour::None ); - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - printResultType( Colour::Error, "** internal error **" ); - break; - } - } - - private: - // Colour::LightGrey - - static Colour::Code dimColour() { return Colour::FileName; } - -#ifdef CATCH_PLATFORM_MAC - static const char* failedString() { return "FAILED"; } - static const char* passedString() { return "PASSED"; } -#else - static const char* failedString() { return "failed"; } - static const char* passedString() { return "passed"; } -#endif - - void printSourceInfo() const { - Colour colourGuard( Colour::FileName ); - stream << result.getSourceInfo() << ":"; - } - - void printResultType( Colour::Code colour, std::string passOrFail ) const { - if( !passOrFail.empty() ) { - { - Colour colourGuard( colour ); - stream << " " << passOrFail; - } - stream << ":"; - } - } - - void printIssue( std::string issue ) const { - stream << " " << issue; - } - - void printExpressionWas() { - if( result.hasExpression() ) { - stream << ";"; - { - Colour colour( dimColour() ); - stream << " expression was:"; - } - printOriginalExpression(); - } - } - - void printOriginalExpression() const { - if( result.hasExpression() ) { - stream << " " << result.getExpression(); - } - } - - void printReconstructedExpression() const { - if( result.hasExpandedExpression() ) { - { - Colour colour( dimColour() ); - stream << " for: "; - } - stream << result.getExpandedExpression(); - } - } - - void printMessage() { - if ( itMessage != messages.end() ) { - stream << " '" << itMessage->message << "'"; - ++itMessage; - } - } - - void printRemainingMessages( Colour::Code colour = dimColour() ) { - if ( itMessage == messages.end() ) - return; - - // using messages.end() directly yields compilation error: - std::vector::const_iterator itEnd = messages.end(); - const std::size_t N = static_cast( std::distance( itMessage, itEnd ) ); - - { - Colour colourGuard( colour ); - stream << " with " << pluralise( N, "message" ) << ":"; - } - - for(; itMessage != itEnd; ) { - // If this assertion is a warning ignore any INFO messages - if( printInfoMessages || itMessage->type != ResultWas::Info ) { - stream << " '" << itMessage->message << "'"; - if ( ++itMessage != itEnd ) { - Colour colourGuard( dimColour() ); - stream << " and"; - } - } - } - } - - private: - std::ostream& stream; - AssertionStats const& stats; - AssertionResult const& result; - std::vector messages; - std::vector::const_iterator itMessage; - bool printInfoMessages; - }; - - // Colour, message variants: - // - white: No tests ran. - // - red: Failed [both/all] N test cases, failed [both/all] M assertions. - // - white: Passed [both/all] N test cases (no assertions). - // - red: Failed N tests cases, failed M assertions. - // - green: Passed [both/all] N tests cases with M assertions. - - std::string bothOrAll( std::size_t count ) const { - return count == 1 ? "" : count == 2 ? "both " : "all " ; - } - - void printTotals( const Totals& totals ) const { - if( totals.testCases.total() == 0 ) { - stream << "No tests ran."; - } - else if( totals.testCases.failed == totals.testCases.total() ) { - Colour colour( Colour::ResultError ); - const std::string qualify_assertions_failed = - totals.assertions.failed == totals.assertions.total() ? - bothOrAll( totals.assertions.failed ) : ""; - stream << - "Failed " << bothOrAll( totals.testCases.failed ) - << pluralise( totals.testCases.failed, "test case" ) << ", " - "failed " << qualify_assertions_failed << - pluralise( totals.assertions.failed, "assertion" ) << "."; - } - else if( totals.assertions.total() == 0 ) { - stream << - "Passed " << bothOrAll( totals.testCases.total() ) - << pluralise( totals.testCases.total(), "test case" ) - << " (no assertions)."; - } - else if( totals.assertions.failed ) { - Colour colour( Colour::ResultError ); - stream << - "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", " - "failed " << pluralise( totals.assertions.failed, "assertion" ) << "."; - } - else { - Colour colour( Colour::ResultSuccess ); - stream << - "Passed " << bothOrAll( totals.testCases.passed ) - << pluralise( totals.testCases.passed, "test case" ) << - " with " << pluralise( totals.assertions.passed, "assertion" ) << "."; - } - } - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter ) - -} // end namespace Catch - -namespace Catch { - NonCopyable::~NonCopyable() {} - IShared::~IShared() {} - StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {} - IContext::~IContext() {} - IResultCapture::~IResultCapture() {} - ITestCase::~ITestCase() {} - ITestCaseRegistry::~ITestCaseRegistry() {} - IRegistryHub::~IRegistryHub() {} - IMutableRegistryHub::~IMutableRegistryHub() {} - IExceptionTranslator::~IExceptionTranslator() {} - IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {} - IReporter::~IReporter() {} - IReporterFactory::~IReporterFactory() {} - IReporterRegistry::~IReporterRegistry() {} - IStreamingReporter::~IStreamingReporter() {} - AssertionStats::~AssertionStats() {} - SectionStats::~SectionStats() {} - TestCaseStats::~TestCaseStats() {} - TestGroupStats::~TestGroupStats() {} - TestRunStats::~TestRunStats() {} - CumulativeReporterBase::SectionNode::~SectionNode() {} - CumulativeReporterBase::~CumulativeReporterBase() {} - - StreamingReporterBase::~StreamingReporterBase() {} - ConsoleReporter::~ConsoleReporter() {} - CompactReporter::~CompactReporter() {} - IRunner::~IRunner() {} - IMutableContext::~IMutableContext() {} - IConfig::~IConfig() {} - XmlReporter::~XmlReporter() {} - JunitReporter::~JunitReporter() {} - TestRegistry::~TestRegistry() {} - FreeFunctionTestCase::~FreeFunctionTestCase() {} - IGeneratorInfo::~IGeneratorInfo() {} - IGeneratorsForTest::~IGeneratorsForTest() {} - TestSpec::Pattern::~Pattern() {} - TestSpec::NamePattern::~NamePattern() {} - TestSpec::TagPattern::~TagPattern() {} - TestSpec::ExcludedPattern::~ExcludedPattern() {} - - Matchers::Impl::StdString::Equals::~Equals() {} - Matchers::Impl::StdString::Contains::~Contains() {} - Matchers::Impl::StdString::StartsWith::~StartsWith() {} - Matchers::Impl::StdString::EndsWith::~EndsWith() {} - - void Config::dummy() {} -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -#endif - -#ifdef CATCH_CONFIG_MAIN -// #included from: internal/catch_default_main.hpp -#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED - -#ifndef __OBJC__ - -// Standard C/C++ main entry point -int main (int argc, char * const argv[]) { - return Catch::Session().run( argc, argv ); -} - -#else // __OBJC__ - -// Objective-C entry point -int main (int argc, char * const argv[]) { -#if !CATCH_ARC_ENABLED - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; -#endif - - Catch::registerTestMethods(); - int result = Catch::Session().run( argc, (char* const*)argv ); - -#if !CATCH_ARC_ENABLED - [pool drain]; -#endif - - return result; -} - -#endif // __OBJC__ - -#endif - -#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED -# undef CLARA_CONFIG_MAIN -#endif - -////// - -// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ -#ifdef CATCH_CONFIG_PREFIX_ALL - -#define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" ) -#define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "CATCH_REQUIRE_FALSE" ) - -#define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS" ) -#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" ) -#define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" ) - -#define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" ) -#define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CATCH_CHECK_FALSE" ) -#define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" ) -#define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" ) -#define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" ) - -#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" ) -#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" ) -#define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" ) - -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" ) -#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" ) - -#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) -#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg ) -#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) -#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) -#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) - #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) - #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) - #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) - #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ ) - #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ ) -#else - #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) - #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) - #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) - #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) - #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg ) - #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg ) -#endif -#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) - -#define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) -#define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) - -#define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) - -// "BDD-style" convenience wrappers -#ifdef CATCH_CONFIG_VARIADIC_MACROS -#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#else -#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags ) -#define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) -#endif -#define CATCH_GIVEN( desc ) CATCH_SECTION( "Given: " desc, "" ) -#define CATCH_WHEN( desc ) CATCH_SECTION( " When: " desc, "" ) -#define CATCH_AND_WHEN( desc ) CATCH_SECTION( " And: " desc, "" ) -#define CATCH_THEN( desc ) CATCH_SECTION( " Then: " desc, "" ) -#define CATCH_AND_THEN( desc ) CATCH_SECTION( " And: " desc, "" ) - -// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required -#else - -#define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" ) -#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "REQUIRE_FALSE" ) - -#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "REQUIRE_THROWS" ) -#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" ) -#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" ) - -#define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" ) -#define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CHECK_FALSE" ) -#define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" ) -#define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" ) -#define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" ) - -#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS" ) -#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" ) -#define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" ) - -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" ) -#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" ) - -#define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) -#define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg ) -#define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) -#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) -#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) - #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) - #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) - #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) - #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ ) - #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ ) -#else - #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) - #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) - #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) - #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) - #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg ) - #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg ) -#endif -#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) - -#define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) -#define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) - -#define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) - -#endif - -#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) - -// "BDD-style" convenience wrappers -#ifdef CATCH_CONFIG_VARIADIC_MACROS -#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#else -#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags ) -#define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) -#endif -#define GIVEN( desc ) SECTION( " Given: " desc, "" ) -#define WHEN( desc ) SECTION( " When: " desc, "" ) -#define AND_WHEN( desc ) SECTION( "And when: " desc, "" ) -#define THEN( desc ) SECTION( " Then: " desc, "" ) -#define AND_THEN( desc ) SECTION( " And: " desc, "" ) - -using Catch::Detail::Approx; - -// #included from: internal/catch_reenable_warnings.h - -#define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(pop) -# else -# pragma clang diagnostic pop -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic pop -#endif - -#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED - diff --git a/third_party/libosmium/test/include/catch_orig.hpp b/third_party/libosmium/test/include/catch_orig.hpp deleted file mode 100644 index de61226cf..000000000 --- a/third_party/libosmium/test/include/catch_orig.hpp +++ /dev/null @@ -1,9416 +0,0 @@ -/* - * Catch v1.2.1 - * Generated: 2015-06-30 18:23:27.961086 - * ---------------------------------------------------------- - * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED - -#define TWOBLUECUBES_CATCH_HPP_INCLUDED - -#ifdef __clang__ -# pragma clang system_header -#elif defined __GNUC__ -# pragma GCC system_header -#endif - -// #included from: internal/catch_suppress_warnings.h - -#define TWOBLUECUBES_CATCH_SUPPRESS_WARNINGS_H_INCLUDED - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(push) -# pragma warning(disable: 161 1682) -# else // __ICC -# pragma clang diagnostic ignored "-Wglobal-constructors" -# pragma clang diagnostic ignored "-Wvariadic-macros" -# pragma clang diagnostic ignored "-Wc99-extensions" -# pragma clang diagnostic ignored "-Wunused-variable" -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wc++98-compat" -# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" -# pragma clang diagnostic ignored "-Wswitch-enum" -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic ignored "-Wvariadic-macros" -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wpadded" -#endif - -#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) -# define CATCH_IMPL -#endif - -#ifdef CATCH_IMPL -# ifndef CLARA_CONFIG_MAIN -# define CLARA_CONFIG_MAIN_NOT_DEFINED -# define CLARA_CONFIG_MAIN -# endif -#endif - -// #included from: internal/catch_notimplemented_exception.h -#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED - -// #included from: catch_common.h -#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED - -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) - -#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr -#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) - -#include -#include -#include - -// #included from: catch_compiler_capabilities.h -#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED - -// Detect a number of compiler features - mostly C++11/14 conformance - by compiler -// The following features are defined: -// -// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? -// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? -// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods -// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? -// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported - -// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? - -// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? - -// In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. -// Many features, at point of detection, define an _INTERNAL_ macro, so they -// can be combined, en-mass, with the _NO_ forms later. - -// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 - -#ifdef __clang__ - -# if __has_feature(cxx_nullptr) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif - -# if __has_feature(cxx_noexcept) -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# endif - -#endif // __clang__ - -//////////////////////////////////////////////////////////////////////////////// -// Borland -#ifdef __BORLANDC__ - -#endif // __BORLANDC__ - -//////////////////////////////////////////////////////////////////////////////// -// EDG -#ifdef __EDG_VERSION__ - -#endif // __EDG_VERSION__ - -//////////////////////////////////////////////////////////////////////////////// -// Digital Mars -#ifdef __DMC__ - -#endif // __DMC__ - -//////////////////////////////////////////////////////////////////////////////// -// GCC -#ifdef __GNUC__ - -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) ) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -#endif - -#endif // __GNUC__ - -//////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#ifdef _MSC_VER - -#if (_MSC_VER >= 1600) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -#endif - -#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) -#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -#endif - -#endif // _MSC_VER - -// Use variadic macros if the compiler supports them -#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ - ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ - ( defined __GNUC__ && __GNUC__ >= 3 ) || \ - ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) - -#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS - -#endif - -//////////////////////////////////////////////////////////////////////////////// -// C++ language feature support - -// catch all support for C++11 -#if (__cplusplus >= 201103L) - -# define CATCH_CPP11_OR_GREATER - -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# endif - -# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# endif - -# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# endif - -#endif // __cplusplus >= 201103L - -// Now set the actual defines based on the above + anything the user has configured -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NULLPTR -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NOEXCEPT -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_GENERATED_METHODS -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_IS_ENUM -#endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_TUPLE -#endif -#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) -#define CATCH_CONFIG_VARIADIC_MACROS -#endif - -// noexcept support: -#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) -# define CATCH_NOEXCEPT noexcept -# define CATCH_NOEXCEPT_IS(x) noexcept(x) -#else -# define CATCH_NOEXCEPT throw() -# define CATCH_NOEXCEPT_IS(x) -#endif - -namespace Catch { - - class NonCopyable { -#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - NonCopyable( NonCopyable const& ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable& operator = ( NonCopyable const& ) = delete; - NonCopyable& operator = ( NonCopyable && ) = delete; -#else - NonCopyable( NonCopyable const& info ); - NonCopyable& operator = ( NonCopyable const& ); -#endif - - protected: - NonCopyable() {} - virtual ~NonCopyable(); - }; - - class SafeBool { - public: - typedef void (SafeBool::*type)() const; - - static type makeSafe( bool value ) { - return value ? &SafeBool::trueValue : 0; - } - private: - void trueValue() const {} - }; - - template - inline void deleteAll( ContainerT& container ) { - typename ContainerT::const_iterator it = container.begin(); - typename ContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete *it; - } - template - inline void deleteAllValues( AssociativeContainerT& container ) { - typename AssociativeContainerT::const_iterator it = container.begin(); - typename AssociativeContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete it->second; - } - - bool startsWith( std::string const& s, std::string const& prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - std::string trim( std::string const& str ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); - - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); - - std::size_t m_count; - std::string m_label; - }; - - struct SourceLineInfo { - - SourceLineInfo(); - SourceLineInfo( char const* _file, std::size_t _line ); - SourceLineInfo( SourceLineInfo const& other ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - SourceLineInfo( SourceLineInfo && ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo& operator = ( SourceLineInfo && ) = default; -# endif - bool empty() const; - bool operator == ( SourceLineInfo const& other ) const; - bool operator < ( SourceLineInfo const& other ) const; - - std::string file; - std::size_t line; - }; - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - - // This is just here to avoid compiler warnings with macro constants and boolean literals - inline bool isTrue( bool value ){ return value; } - inline bool alwaysTrue() { return true; } - inline bool alwaysFalse() { return false; } - - void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); - - // Use this in variadic streaming macros to allow - // >> +StreamEndStop - // as well as - // >> stuff +StreamEndStop - struct StreamEndStop { - std::string operator+() { - return std::string(); - } - }; - template - T const& operator + ( T const& value, StreamEndStop ) { - return value; - } -} - -#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) -#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); - -#include - -namespace Catch { - - class NotImplementedException : public std::exception - { - public: - NotImplementedException( SourceLineInfo const& lineInfo ); - NotImplementedException( NotImplementedException const& ) {} - - virtual ~NotImplementedException() CATCH_NOEXCEPT {} - - virtual const char* what() const CATCH_NOEXCEPT; - - private: - std::string m_what; - SourceLineInfo m_lineInfo; - }; - -} // end namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) - -// #included from: internal/catch_context.h -#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED - -// #included from: catch_interfaces_generators.h -#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED - -#include - -namespace Catch { - - struct IGeneratorInfo { - virtual ~IGeneratorInfo(); - virtual bool moveNext() = 0; - virtual std::size_t getCurrentIndex() const = 0; - }; - - struct IGeneratorsForTest { - virtual ~IGeneratorsForTest(); - - virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; - virtual bool moveNext() = 0; - }; - - IGeneratorsForTest* createGeneratorsForTest(); - -} // end namespace Catch - -// #included from: catch_ptr.hpp -#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - // An intrusive reference counting smart pointer. - // T must implement addRef() and release() methods - // typically implementing the IShared interface - template - class Ptr { - public: - Ptr() : m_p( NULL ){} - Ptr( T* p ) : m_p( p ){ - if( m_p ) - m_p->addRef(); - } - Ptr( Ptr const& other ) : m_p( other.m_p ){ - if( m_p ) - m_p->addRef(); - } - ~Ptr(){ - if( m_p ) - m_p->release(); - } - void reset() { - if( m_p ) - m_p->release(); - m_p = NULL; - } - Ptr& operator = ( T* p ){ - Ptr temp( p ); - swap( temp ); - return *this; - } - Ptr& operator = ( Ptr const& other ){ - Ptr temp( other ); - swap( temp ); - return *this; - } - void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } - T* get() { return m_p; } - const T* get() const{ return m_p; } - T& operator*() const { return *m_p; } - T* operator->() const { return m_p; } - bool operator !() const { return m_p == NULL; } - operator SafeBool::type() const { return SafeBool::makeSafe( m_p != NULL ); } - - private: - T* m_p; - }; - - struct IShared : NonCopyable { - virtual ~IShared(); - virtual void addRef() const = 0; - virtual void release() const = 0; - }; - - template - struct SharedImpl : T { - - SharedImpl() : m_rc( 0 ){} - - virtual void addRef() const { - ++m_rc; - } - virtual void release() const { - if( --m_rc == 0 ) - delete this; - } - - mutable unsigned int m_rc; - }; - -} // end namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -#include -#include -#include - -namespace Catch { - - class TestCase; - class Stream; - struct IResultCapture; - struct IRunner; - struct IGeneratorsForTest; - struct IConfig; - - struct IContext - { - virtual ~IContext(); - - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; - virtual bool advanceGeneratorsForCurrentTest() = 0; - virtual Ptr getConfig() const = 0; - }; - - struct IMutableContext : IContext - { - virtual ~IMutableContext(); - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( Ptr const& config ) = 0; - }; - - IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); - void cleanUpContext(); - Stream createStream( std::string const& streamName ); - -} - -// #included from: internal/catch_test_registry.hpp -#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED - -// #included from: catch_interfaces_testcase.h -#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED - -#include - -namespace Catch { - - class TestSpec; - - struct ITestCase : IShared { - virtual void invoke () const = 0; - protected: - virtual ~ITestCase(); - }; - - class TestCase; - struct IConfig; - - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector& matchingTestCases, bool negated = false ) const = 0; - - }; -} - -namespace Catch { - -template -class MethodTestCase : public SharedImpl { - -public: - MethodTestCase( void (C::*method)() ) : m_method( method ) {} - - virtual void invoke() const { - C obj; - (obj.*m_method)(); - } - -private: - virtual ~MethodTestCase() {} - - void (C::*m_method)(); -}; - -typedef void(*TestFunction)(); - -struct NameAndDesc { - NameAndDesc( const char* _name = "", const char* _description= "" ) - : name( _name ), description( _description ) - {} - - const char* name; - const char* description; -}; - -struct AutoReg { - - AutoReg( TestFunction function, - SourceLineInfo const& lineInfo, - NameAndDesc const& nameAndDesc ); - - template - AutoReg( void (C::*method)(), - char const* className, - NameAndDesc const& nameAndDesc, - SourceLineInfo const& lineInfo ) { - registerTestCase( new MethodTestCase( method ), - className, - nameAndDesc, - lineInfo ); - } - - void registerTestCase( ITestCase* testCase, - char const* className, - NameAndDesc const& nameAndDesc, - SourceLineInfo const& lineInfo ); - - ~AutoReg(); - -private: - AutoReg( AutoReg const& ); - void operator= ( AutoReg const& ); -}; - -} // end namespace Catch - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TESTCASE( ... ) \ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )(); \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )() - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... )\ - namespace{ \ - struct INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) : ClassName{ \ - void test(); \ - }; \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \ - } \ - void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test() - -#else - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )(); \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\ - static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )() - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\ - namespace{ \ - struct INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) : ClassName{ \ - void test(); \ - }; \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \ - } \ - void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test() - -#endif - -// #included from: internal/catch_capture.hpp -#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED - -// #included from: catch_result_builder.h -#define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED - -// #included from: catch_result_type.h -#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED - -namespace Catch { - - // ResultWas::OfType enum - struct ResultWas { enum OfType { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, - - FailureBit = 0x10, - - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, - - Exception = 0x100 | FailureBit, - - ThrewException = Exception | 1, - DidntThrowException = Exception | 2, - - FatalErrorCondition = 0x200 | FailureBit - - }; }; - - inline bool isOk( ResultWas::OfType resultType ) { - return ( resultType & ResultWas::FailureBit ) == 0; - } - inline bool isJustInfo( int flags ) { - return flags == ResultWas::Info; - } - - // ResultDisposition::Flags enum - struct ResultDisposition { enum Flags { - Normal = 0x01, - - ContinueOnFailure = 0x02, // Failures fail test, but execution continues - FalseTest = 0x04, // Prefix expression with ! - SuppressFail = 0x08 // Failures are reported but do not fail the test - }; }; - - inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { - return static_cast( static_cast( lhs ) | static_cast( rhs ) ); - } - - inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } - inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } - inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } - -} // end namespace Catch - -// #included from: catch_assertionresult.h -#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED - -#include - -namespace Catch { - - struct AssertionInfo - { - AssertionInfo() {} - AssertionInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - std::string const& _capturedExpression, - ResultDisposition::Flags _resultDisposition ); - - std::string macroName; - SourceLineInfo lineInfo; - std::string capturedExpression; - ResultDisposition::Flags resultDisposition; - }; - - struct AssertionResultData - { - AssertionResultData() : resultType( ResultWas::Unknown ) {} - - std::string reconstructedExpression; - std::string message; - ResultWas::OfType resultType; - }; - - class AssertionResult { - public: - AssertionResult(); - AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); - ~AssertionResult(); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - AssertionResult( AssertionResult const& ) = default; - AssertionResult( AssertionResult && ) = default; - AssertionResult& operator = ( AssertionResult const& ) = default; - AssertionResult& operator = ( AssertionResult && ) = default; -# endif - - bool isOk() const; - bool succeeded() const; - ResultWas::OfType getResultType() const; - bool hasExpression() const; - bool hasMessage() const; - std::string getExpression() const; - std::string getExpressionInMacro() const; - bool hasExpandedExpression() const; - std::string getExpandedExpression() const; - std::string getMessage() const; - SourceLineInfo getSourceInfo() const; - std::string getTestMacroName() const; - - protected: - AssertionInfo m_info; - AssertionResultData m_resultData; - }; - -} // end namespace Catch - -namespace Catch { - - struct TestFailureException{}; - - template class ExpressionLhs; - - struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; - - struct CopyableStream { - CopyableStream() {} - CopyableStream( CopyableStream const& other ) { - oss << other.oss.str(); - } - CopyableStream& operator=( CopyableStream const& other ) { - oss.str(""); - oss << other.oss.str(); - return *this; - } - std::ostringstream oss; - }; - - class ResultBuilder { - public: - ResultBuilder( char const* macroName, - SourceLineInfo const& lineInfo, - char const* capturedExpression, - ResultDisposition::Flags resultDisposition ); - - template - ExpressionLhs operator <= ( T const& operand ); - ExpressionLhs operator <= ( bool value ); - - template - ResultBuilder& operator << ( T const& value ) { - m_stream.oss << value; - return *this; - } - - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); - - ResultBuilder& setResultType( ResultWas::OfType result ); - ResultBuilder& setResultType( bool result ); - ResultBuilder& setLhs( std::string const& lhs ); - ResultBuilder& setRhs( std::string const& rhs ); - ResultBuilder& setOp( std::string const& op ); - - void endExpression(); - - std::string reconstructExpression() const; - AssertionResult build() const; - - void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); - void captureResult( ResultWas::OfType resultType ); - void captureExpression(); - void react(); - bool shouldDebugBreak() const; - bool allowThrows() const; - - private: - AssertionInfo m_assertionInfo; - AssertionResultData m_data; - struct ExprComponents { - ExprComponents() : testFalse( false ) {} - bool testFalse; - std::string lhs, rhs, op; - } m_exprComponents; - CopyableStream m_stream; - - bool m_shouldDebugBreak; - bool m_shouldThrow; - }; - -} // namespace Catch - -// Include after due to circular dependency: -// #included from: catch_expression_lhs.hpp -#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED - -// #included from: catch_evaluate.hpp -#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4389) // '==' : signed/unsigned mismatch -#endif - -#include - -namespace Catch { -namespace Internal { - - enum Operator { - IsEqualTo, - IsNotEqualTo, - IsLessThan, - IsGreaterThan, - IsLessThanOrEqualTo, - IsGreaterThanOrEqualTo - }; - - template struct OperatorTraits { static const char* getName(){ return "*error*"; } }; - template<> struct OperatorTraits { static const char* getName(){ return "=="; } }; - template<> struct OperatorTraits { static const char* getName(){ return "!="; } }; - template<> struct OperatorTraits { static const char* getName(){ return "<"; } }; - template<> struct OperatorTraits { static const char* getName(){ return ">"; } }; - template<> struct OperatorTraits { static const char* getName(){ return "<="; } }; - template<> struct OperatorTraits{ static const char* getName(){ return ">="; } }; - - template - inline T& opCast(T const& t) { return const_cast(t); } - -// nullptr_t support based on pull request #154 from Konstantin Baumann -#ifdef CATCH_CONFIG_CPP11_NULLPTR - inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; } -#endif // CATCH_CONFIG_CPP11_NULLPTR - - // So the compare overloads can be operator agnostic we convey the operator as a template - // enum, which is used to specialise an Evaluator for doing the comparison. - template - class Evaluator{}; - - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs) { - return opCast( lhs ) == opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) != opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) < opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) > opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) >= opCast( rhs ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return opCast( lhs ) <= opCast( rhs ); - } - }; - - template - bool applyEvaluator( T1 const& lhs, T2 const& rhs ) { - return Evaluator::evaluate( lhs, rhs ); - } - - // This level of indirection allows us to specialise for integer types - // to avoid signed/ unsigned warnings - - // "base" overload - template - bool compare( T1 const& lhs, T2 const& rhs ) { - return Evaluator::evaluate( lhs, rhs ); - } - - // unsigned X to int - template bool compare( unsigned int lhs, int rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned long lhs, int rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned char lhs, int rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - - // unsigned X to long - template bool compare( unsigned int lhs, long rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned long lhs, long rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned char lhs, long rhs ) { - return applyEvaluator( lhs, static_cast( rhs ) ); - } - - // int to unsigned X - template bool compare( int lhs, unsigned int rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( int lhs, unsigned long rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( int lhs, unsigned char rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - - // long to unsigned X - template bool compare( long lhs, unsigned int rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long lhs, unsigned long rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long lhs, unsigned char rhs ) { - return applyEvaluator( static_cast( lhs ), rhs ); - } - - // pointer to long (when comparing against NULL) - template bool compare( long lhs, T* rhs ) { - return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } - template bool compare( T* lhs, long rhs ) { - return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); - } - - // pointer to int (when comparing against NULL) - template bool compare( int lhs, T* rhs ) { - return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } - template bool compare( T* lhs, int rhs ) { - return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); - } - -#ifdef CATCH_CONFIG_CPP11_NULLPTR - // pointer to nullptr_t (when comparing against nullptr) - template bool compare( std::nullptr_t, T* rhs ) { - return Evaluator::evaluate( NULL, rhs ); - } - template bool compare( T* lhs, std::nullptr_t ) { - return Evaluator::evaluate( lhs, NULL ); - } -#endif // CATCH_CONFIG_CPP11_NULLPTR - -} // end of namespace Internal -} // end of namespace Catch - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// #included from: catch_tostring.h -#define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED - -#include -#include -#include -#include -#include - -#ifdef __OBJC__ -// #included from: catch_objc_arc.hpp -#define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED - -#import - -#ifdef __has_feature -#define CATCH_ARC_ENABLED __has_feature(objc_arc) -#else -#define CATCH_ARC_ENABLED 0 -#endif - -void arcSafeRelease( NSObject* obj ); -id performOptionalSelector( id obj, SEL sel ); - -#if !CATCH_ARC_ENABLED -inline void arcSafeRelease( NSObject* obj ) { - [obj release]; -} -inline id performOptionalSelector( id obj, SEL sel ) { - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; - return nil; -} -#define CATCH_UNSAFE_UNRETAINED -#define CATCH_ARC_STRONG -#else -inline void arcSafeRelease( NSObject* ){} -inline id performOptionalSelector( id obj, SEL sel ) { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" -#endif - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - return nil; -} -#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained -#define CATCH_ARC_STRONG __strong -#endif - -#endif - -#ifdef CATCH_CONFIG_CPP11_TUPLE -#include -#endif - -#ifdef CATCH_CONFIG_CPP11_IS_ENUM -#include -#endif - -namespace Catch { - -// Why we're here. -template -std::string toString( T const& value ); - -// Built in overloads - -std::string toString( std::string const& value ); -std::string toString( std::wstring const& value ); -std::string toString( const char* const value ); -std::string toString( char* const value ); -std::string toString( const wchar_t* const value ); -std::string toString( wchar_t* const value ); -std::string toString( int value ); -std::string toString( unsigned long value ); -std::string toString( unsigned int value ); -std::string toString( const double value ); -std::string toString( const float value ); -std::string toString( bool value ); -std::string toString( char value ); -std::string toString( signed char value ); -std::string toString( unsigned char value ); - -#ifdef CATCH_CONFIG_CPP11_NULLPTR -std::string toString( std::nullptr_t ); -#endif - -#ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ); - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); - std::string toString( NSObject* const& nsObject ); -#endif - -namespace Detail { - - extern std::string unprintableString; - - struct BorgType { - template BorgType( T const& ); - }; - - struct TrueType { char sizer[1]; }; - struct FalseType { char sizer[2]; }; - - TrueType& testStreamable( std::ostream& ); - FalseType testStreamable( FalseType ); - - FalseType operator<<( std::ostream const&, BorgType const& ); - - template - struct IsStreamInsertable { - static std::ostream &s; - static T const&t; - enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) }; - }; - -#if defined(CATCH_CONFIG_CPP11_IS_ENUM) - template::value - > - struct EnumStringMaker - { - static std::string convert( T const& ) { return unprintableString; } - }; - - template - struct EnumStringMaker - { - static std::string convert( T const& v ) - { - return ::Catch::toString( - static_cast::type>(v) - ); - } - }; -#endif - template - struct StringMakerBase { -#if defined(CATCH_CONFIG_CPP11_IS_ENUM) - template - static std::string convert( T const& v ) - { - return EnumStringMaker::convert( v ); - } -#else - template - static std::string convert( T const& ) { return unprintableString; } -#endif - }; - - template<> - struct StringMakerBase { - template - static std::string convert( T const& _value ) { - std::ostringstream oss; - oss << _value; - return oss.str(); - } - }; - - std::string rawMemoryToString( const void *object, std::size_t size ); - - template - inline std::string rawMemoryToString( const T& object ) { - return rawMemoryToString( &object, sizeof(object) ); - } - -} // end namespace Detail - -template -struct StringMaker : - Detail::StringMakerBase::value> {}; - -template -struct StringMaker { - template - static std::string convert( U* p ) { - if( !p ) - return INTERNAL_CATCH_STRINGIFY( NULL ); - else - return Detail::rawMemoryToString( p ); - } -}; - -template -struct StringMaker { - static std::string convert( R C::* p ) { - if( !p ) - return INTERNAL_CATCH_STRINGIFY( NULL ); - else - return Detail::rawMemoryToString( p ); - } -}; - -namespace Detail { - template - std::string rangeToString( InputIterator first, InputIterator last ); -} - -//template -//struct StringMaker > { -// static std::string convert( std::vector const& v ) { -// return Detail::rangeToString( v.begin(), v.end() ); -// } -//}; - -template -std::string toString( std::vector const& v ) { - return Detail::rangeToString( v.begin(), v.end() ); -} - -#ifdef CATCH_CONFIG_CPP11_TUPLE - -// toString for tuples -namespace TupleDetail { - template< - typename Tuple, - std::size_t N = 0, - bool = (N < std::tuple_size::value) - > - struct ElementPrinter { - static void print( const Tuple& tuple, std::ostream& os ) - { - os << ( N ? ", " : " " ) - << Catch::toString(std::get(tuple)); - ElementPrinter::print(tuple,os); - } - }; - - template< - typename Tuple, - std::size_t N - > - struct ElementPrinter { - static void print( const Tuple&, std::ostream& ) {} - }; - -} - -template -struct StringMaker> { - - static std::string convert( const std::tuple& tuple ) - { - std::ostringstream os; - os << '{'; - TupleDetail::ElementPrinter>::print( tuple, os ); - os << " }"; - return os.str(); - } -}; -#endif // CATCH_CONFIG_CPP11_TUPLE - -namespace Detail { - template - std::string makeString( T const& value ) { - return StringMaker::convert( value ); - } -} // end namespace Detail - -/// \brief converts any type to a string -/// -/// The default template forwards on to ostringstream - except when an -/// ostringstream overload does not exist - in which case it attempts to detect -/// that and writes {?}. -/// Overload (not specialise) this template for custom typs that you don't want -/// to provide an ostream overload for. -template -std::string toString( T const& value ) { - return StringMaker::convert( value ); -} - - namespace Detail { - template - std::string rangeToString( InputIterator first, InputIterator last ) { - std::ostringstream oss; - oss << "{ "; - if( first != last ) { - oss << Catch::toString( *first ); - for( ++first ; first != last ; ++first ) - oss << ", " << Catch::toString( *first ); - } - oss << " }"; - return oss.str(); - } -} - -} // end namespace Catch - -namespace Catch { - -// Wraps the LHS of an expression and captures the operator and RHS (if any) - -// wrapping them all in a ResultBuilder object -template -class ExpressionLhs { - ExpressionLhs& operator = ( ExpressionLhs const& ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - ExpressionLhs& operator = ( ExpressionLhs && ) = delete; -# endif - -public: - ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - ExpressionLhs( ExpressionLhs const& ) = default; - ExpressionLhs( ExpressionLhs && ) = default; -# endif - - template - ResultBuilder& operator == ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator != ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator < ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator > ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator <= ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - template - ResultBuilder& operator >= ( RhsT const& rhs ) { - return captureExpression( rhs ); - } - - ResultBuilder& operator == ( bool rhs ) { - return captureExpression( rhs ); - } - - ResultBuilder& operator != ( bool rhs ) { - return captureExpression( rhs ); - } - - void endExpression() { - bool value = m_lhs ? true : false; - m_rb - .setLhs( Catch::toString( value ) ) - .setResultType( value ) - .endExpression(); - } - - // Only simple binary expressions are allowed on the LHS. - // If more complex compositions are required then place the sub expression in parentheses - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); - template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); - -private: - template - ResultBuilder& captureExpression( RhsT const& rhs ) { - return m_rb - .setResultType( Internal::compare( m_lhs, rhs ) ) - .setLhs( Catch::toString( m_lhs ) ) - .setRhs( Catch::toString( rhs ) ) - .setOp( Internal::OperatorTraits::getName() ); - } - -private: - ResultBuilder& m_rb; - T m_lhs; -}; - -} // end namespace Catch - - -namespace Catch { - - template - inline ExpressionLhs ResultBuilder::operator <= ( T const& operand ) { - return ExpressionLhs( *this, operand ); - } - - inline ExpressionLhs ResultBuilder::operator <= ( bool value ) { - return ExpressionLhs( *this, value ); - } - -} // namespace Catch - -// #included from: catch_message.h -#define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED - -#include - -namespace Catch { - - struct MessageInfo { - MessageInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ); - - std::string macroName; - SourceLineInfo lineInfo; - ResultWas::OfType type; - std::string message; - unsigned int sequence; - - bool operator == ( MessageInfo const& other ) const { - return sequence == other.sequence; - } - bool operator < ( MessageInfo const& other ) const { - return sequence < other.sequence; - } - private: - static unsigned int globalCount; - }; - - struct MessageBuilder { - MessageBuilder( std::string const& macroName, - SourceLineInfo const& lineInfo, - ResultWas::OfType type ) - : m_info( macroName, lineInfo, type ) - {} - - template - MessageBuilder& operator << ( T const& value ) { - m_stream << value; - return *this; - } - - MessageInfo m_info; - std::ostringstream m_stream; - }; - - class ScopedMessage { - public: - ScopedMessage( MessageBuilder const& builder ); - ScopedMessage( ScopedMessage const& other ); - ~ScopedMessage(); - - MessageInfo m_info; - }; - -} // end namespace Catch - -// #included from: catch_interfaces_capture.h -#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED - -#include - -namespace Catch { - - class TestCase; - class AssertionResult; - struct AssertionInfo; - struct SectionInfo; - struct MessageInfo; - class ScopedMessageBuilder; - struct Counts; - - struct IResultCapture { - - virtual ~IResultCapture(); - - virtual void assertionEnded( AssertionResult const& result ) = 0; - virtual bool sectionStarted( SectionInfo const& sectionInfo, - Counts& assertions ) = 0; - virtual void sectionEnded( SectionInfo const& name, Counts const& assertions, double _durationInSeconds ) = 0; - virtual void pushScopedMessage( MessageInfo const& message ) = 0; - virtual void popScopedMessage( MessageInfo const& message ) = 0; - - virtual std::string getCurrentTestName() const = 0; - virtual const AssertionResult* getLastResult() const = 0; - - virtual void handleFatalErrorCondition( std::string const& message ) = 0; - }; - - IResultCapture& getResultCapture(); -} - -// #included from: catch_debugger.h -#define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED - -// #included from: catch_platform.h -#define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED - -#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_MAC -#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_IPHONE -#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) -#define CATCH_PLATFORM_WINDOWS -#endif - -#include - -namespace Catch{ - - bool isDebuggerActive(); - void writeToDebugConsole( std::string const& text ); -} - -#ifdef CATCH_PLATFORM_MAC - - // The following code snippet based on: - // http://cocoawithlove.com/2008/03/break-into-debugger.html - #ifdef DEBUG - #if defined(__ppc64__) || defined(__ppc__) - #define CATCH_BREAK_INTO_DEBUGGER() \ - if( Catch::isDebuggerActive() ) { \ - __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ - : : : "memory","r0","r3","r4" ); \ - } - #else - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );} - #endif - #endif - -#elif defined(_MSC_VER) - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { __debugbreak(); } -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) void __stdcall DebugBreak(); - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { DebugBreak(); } -#endif - -#ifndef CATCH_BREAK_INTO_DEBUGGER -#define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); -#endif - -// #included from: catch_interfaces_runner.h -#define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED - -namespace Catch { - class TestCase; - - struct IRunner { - virtual ~IRunner(); - virtual bool aborting() const = 0; - }; -} - -/////////////////////////////////////////////////////////////////////////////// -// In the event of a failure works out if the debugger needs to be invoked -// and/or an exception thrown and takes appropriate action. -// This needs to be done as a macro so the debugger will stop in the user -// source code rather than in Catch library code -#define INTERNAL_CATCH_REACT( resultBuilder ) \ - if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \ - resultBuilder.react(); - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - try { \ - ( __catchResult <= expr ).endExpression(); \ - } \ - catch( ... ) { \ - __catchResult.useActiveException( Catch::ResultDisposition::Normal ); \ - } \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::isTrue( false && (expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \ - INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ - if( Catch::getResultCapture().getLastResult()->succeeded() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \ - INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ - if( !Catch::getResultCapture().getLastResult()->succeeded() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - try { \ - expr; \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - } \ - catch( ... ) { \ - __catchResult.useActiveException( resultDisposition ); \ - } \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS( expr, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - if( __catchResult.allowThrows() ) \ - try { \ - expr; \ - __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ - } \ - catch( ... ) { \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - } \ - else \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ - if( __catchResult.allowThrows() ) \ - try { \ - expr; \ - __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ - } \ - catch( exceptionType ) { \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - } \ - catch( ... ) { \ - __catchResult.useActiveException( resultDisposition ); \ - } \ - else \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -/////////////////////////////////////////////////////////////////////////////// -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \ - __catchResult.captureResult( messageType ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) -#else - #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ - __catchResult << log + ::Catch::StreamEndStop(); \ - __catchResult.captureResult( messageType ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) -#endif - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_INFO( log, macroName ) \ - Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log; - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \ - do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg " " #matcher, resultDisposition ); \ - try { \ - std::string matcherAsString = ::Catch::Matchers::matcher.toString(); \ - __catchResult \ - .setLhs( Catch::toString( arg ) ) \ - .setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \ - .setOp( "matches" ) \ - .setResultType( ::Catch::Matchers::matcher.match( arg ) ); \ - __catchResult.captureExpression(); \ - } catch( ... ) { \ - __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \ - } \ - INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse() ) - -// #included from: internal/catch_section.h -#define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED - -// #included from: catch_section_info.h -#define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED - -namespace Catch { - - struct SectionInfo { - SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description = std::string() ); - - std::string name; - std::string description; - SourceLineInfo lineInfo; - }; - -} // end namespace Catch - -// #included from: catch_totals.hpp -#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED - -#include - -namespace Catch { - - struct Counts { - Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {} - - Counts operator - ( Counts const& other ) const { - Counts diff; - diff.passed = passed - other.passed; - diff.failed = failed - other.failed; - diff.failedButOk = failedButOk - other.failedButOk; - return diff; - } - Counts& operator += ( Counts const& other ) { - passed += other.passed; - failed += other.failed; - failedButOk += other.failedButOk; - return *this; - } - - std::size_t total() const { - return passed + failed + failedButOk; - } - bool allPassed() const { - return failed == 0 && failedButOk == 0; - } - bool allOk() const { - return failed == 0; - } - - std::size_t passed; - std::size_t failed; - std::size_t failedButOk; - }; - - struct Totals { - - Totals operator - ( Totals const& other ) const { - Totals diff; - diff.assertions = assertions - other.assertions; - diff.testCases = testCases - other.testCases; - return diff; - } - - Totals delta( Totals const& prevTotals ) const { - Totals diff = *this - prevTotals; - if( diff.assertions.failed > 0 ) - ++diff.testCases.failed; - else if( diff.assertions.failedButOk > 0 ) - ++diff.testCases.failedButOk; - else - ++diff.testCases.passed; - return diff; - } - - Totals& operator += ( Totals const& other ) { - assertions += other.assertions; - testCases += other.testCases; - return *this; - } - - Counts assertions; - Counts testCases; - }; -} - -// #included from: catch_timer.h -#define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED - -#ifdef CATCH_PLATFORM_WINDOWS -typedef unsigned long long uint64_t; -#else -#include -#endif - -namespace Catch { - - class Timer { - public: - Timer() : m_ticks( 0 ) {} - void start(); - unsigned int getElapsedMicroseconds() const; - unsigned int getElapsedMilliseconds() const; - double getElapsedSeconds() const; - - private: - uint64_t m_ticks; - }; - -} // namespace Catch - -#include - -namespace Catch { - - class Section : NonCopyable { - public: - Section( SectionInfo const& info ); - ~Section(); - - // This indicates whether the section should be executed or not - operator bool() const; - - private: - SectionInfo m_info; - - std::string m_name; - Counts m_assertions; - bool m_sectionIncluded; - Timer m_timer; - }; - -} // end namespace Catch - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define INTERNAL_CATCH_SECTION( ... ) \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) -#else - #define INTERNAL_CATCH_SECTION( name, desc ) \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) ) -#endif - -// #included from: internal/catch_generators.hpp -#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED - -#include -#include -#include -#include - -namespace Catch { - -template -struct IGenerator { - virtual ~IGenerator() {} - virtual T getValue( std::size_t index ) const = 0; - virtual std::size_t size () const = 0; -}; - -template -class BetweenGenerator : public IGenerator { -public: - BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} - - virtual T getValue( std::size_t index ) const { - return m_from+static_cast( index ); - } - - virtual std::size_t size() const { - return static_cast( 1+m_to-m_from ); - } - -private: - - T m_from; - T m_to; -}; - -template -class ValuesGenerator : public IGenerator { -public: - ValuesGenerator(){} - - void add( T value ) { - m_values.push_back( value ); - } - - virtual T getValue( std::size_t index ) const { - return m_values[index]; - } - - virtual std::size_t size() const { - return m_values.size(); - } - -private: - std::vector m_values; -}; - -template -class CompositeGenerator { -public: - CompositeGenerator() : m_totalSize( 0 ) {} - - // *** Move semantics, similar to auto_ptr *** - CompositeGenerator( CompositeGenerator& other ) - : m_fileInfo( other.m_fileInfo ), - m_totalSize( 0 ) - { - move( other ); - } - - CompositeGenerator& setFileInfo( const char* fileInfo ) { - m_fileInfo = fileInfo; - return *this; - } - - ~CompositeGenerator() { - deleteAll( m_composed ); - } - - operator T () const { - size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); - - typename std::vector*>::const_iterator it = m_composed.begin(); - typename std::vector*>::const_iterator itEnd = m_composed.end(); - for( size_t index = 0; it != itEnd; ++it ) - { - const IGenerator* generator = *it; - if( overallIndex >= index && overallIndex < index + generator->size() ) - { - return generator->getValue( overallIndex-index ); - } - index += generator->size(); - } - CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); - return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so - } - - void add( const IGenerator* generator ) { - m_totalSize += generator->size(); - m_composed.push_back( generator ); - } - - CompositeGenerator& then( CompositeGenerator& other ) { - move( other ); - return *this; - } - - CompositeGenerator& then( T value ) { - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( value ); - add( valuesGen ); - return *this; - } - -private: - - void move( CompositeGenerator& other ) { - std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) ); - m_totalSize += other.m_totalSize; - other.m_composed.clear(); - } - - std::vector*> m_composed; - std::string m_fileInfo; - size_t m_totalSize; -}; - -namespace Generators -{ - template - CompositeGenerator between( T from, T to ) { - CompositeGenerator generators; - generators.add( new BetweenGenerator( from, to ) ); - return generators; - } - - template - CompositeGenerator values( T val1, T val2 ) { - CompositeGenerator generators; - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - generators.add( valuesGen ); - return generators; - } - - template - CompositeGenerator values( T val1, T val2, T val3 ){ - CompositeGenerator generators; - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - valuesGen->add( val3 ); - generators.add( valuesGen ); - return generators; - } - - template - CompositeGenerator values( T val1, T val2, T val3, T val4 ) { - CompositeGenerator generators; - ValuesGenerator* valuesGen = new ValuesGenerator(); - valuesGen->add( val1 ); - valuesGen->add( val2 ); - valuesGen->add( val3 ); - valuesGen->add( val4 ); - generators.add( valuesGen ); - return generators; - } - -} // end namespace Generators - -using namespace Generators; - -} // end namespace Catch - -#define INTERNAL_CATCH_LINESTR2( line ) #line -#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) - -#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) - -// #included from: internal/catch_interfaces_exception.h -#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED - -#include -// #included from: catch_interfaces_registry_hub.h -#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED - -#include - -namespace Catch { - - class TestCase; - struct ITestCaseRegistry; - struct IExceptionTranslatorRegistry; - struct IExceptionTranslator; - struct IReporterRegistry; - struct IReporterFactory; - - struct IRegistryHub { - virtual ~IRegistryHub(); - - virtual IReporterRegistry const& getReporterRegistry() const = 0; - virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; - }; - - struct IMutableRegistryHub { - virtual ~IMutableRegistryHub(); - virtual void registerReporter( std::string const& name, IReporterFactory* factory ) = 0; - virtual void registerTest( TestCase const& testInfo ) = 0; - virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; - }; - - IRegistryHub& getRegistryHub(); - IMutableRegistryHub& getMutableRegistryHub(); - void cleanUp(); - std::string translateActiveException(); - -} - - -namespace Catch { - - typedef std::string(*exceptionTranslateFunction)(); - - struct IExceptionTranslator { - virtual ~IExceptionTranslator(); - virtual std::string translate() const = 0; - }; - - struct IExceptionTranslatorRegistry { - virtual ~IExceptionTranslatorRegistry(); - - virtual std::string translateActiveException() const = 0; - }; - - class ExceptionTranslatorRegistrar { - template - class ExceptionTranslator : public IExceptionTranslator { - public: - - ExceptionTranslator( std::string(*translateFunction)( T& ) ) - : m_translateFunction( translateFunction ) - {} - - virtual std::string translate() const { - try { - throw; - } - catch( T& ex ) { - return m_translateFunction( ex ); - } - } - - protected: - std::string(*m_translateFunction)( T& ); - }; - - public: - template - ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { - getMutableRegistryHub().registerTranslator - ( new ExceptionTranslator( translateFunction ) ); - } - }; -} - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) \ - static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ); \ - namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ) ); }\ - static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ) - -// #included from: internal/catch_approx.hpp -#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED - -#include -#include - -namespace Catch { -namespace Detail { - - class Approx { - public: - explicit Approx ( double value ) - : m_epsilon( std::numeric_limits::epsilon()*100 ), - m_scale( 1.0 ), - m_value( value ) - {} - - Approx( Approx const& other ) - : m_epsilon( other.m_epsilon ), - m_scale( other.m_scale ), - m_value( other.m_value ) - {} - - static Approx custom() { - return Approx( 0 ); - } - - Approx operator()( double value ) { - Approx approx( value ); - approx.epsilon( m_epsilon ); - approx.scale( m_scale ); - return approx; - } - - friend bool operator == ( double lhs, Approx const& rhs ) { - // Thanks to Richard Harris for his help refining this formula - return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) ); - } - - friend bool operator == ( Approx const& lhs, double rhs ) { - return operator==( rhs, lhs ); - } - - friend bool operator != ( double lhs, Approx const& rhs ) { - return !operator==( lhs, rhs ); - } - - friend bool operator != ( Approx const& lhs, double rhs ) { - return !operator==( rhs, lhs ); - } - - Approx& epsilon( double newEpsilon ) { - m_epsilon = newEpsilon; - return *this; - } - - Approx& scale( double newScale ) { - m_scale = newScale; - return *this; - } - - std::string toString() const { - std::ostringstream oss; - oss << "Approx( " << Catch::toString( m_value ) << " )"; - return oss.str(); - } - - private: - double m_epsilon; - double m_scale; - double m_value; - }; -} - -template<> -inline std::string toString( Detail::Approx const& value ) { - return value.toString(); -} - -} // end namespace Catch - -// #included from: internal/catch_matchers.hpp -#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED - -namespace Catch { -namespace Matchers { - namespace Impl { - - template - struct Matcher : SharedImpl - { - typedef ExpressionT ExpressionType; - - virtual ~Matcher() {} - virtual Ptr clone() const = 0; - virtual bool match( ExpressionT const& expr ) const = 0; - virtual std::string toString() const = 0; - }; - - template - struct MatcherImpl : Matcher { - - virtual Ptr > clone() const { - return Ptr >( new DerivedT( static_cast( *this ) ) ); - } - }; - - namespace Generic { - - template - class AllOf : public MatcherImpl, ExpressionT> { - public: - - AllOf() {} - AllOf( AllOf const& other ) : m_matchers( other.m_matchers ) {} - - AllOf& add( Matcher const& matcher ) { - m_matchers.push_back( matcher.clone() ); - return *this; - } - virtual bool match( ExpressionT const& expr ) const - { - for( std::size_t i = 0; i < m_matchers.size(); ++i ) - if( !m_matchers[i]->match( expr ) ) - return false; - return true; - } - virtual std::string toString() const { - std::ostringstream oss; - oss << "( "; - for( std::size_t i = 0; i < m_matchers.size(); ++i ) { - if( i != 0 ) - oss << " and "; - oss << m_matchers[i]->toString(); - } - oss << " )"; - return oss.str(); - } - - private: - std::vector > > m_matchers; - }; - - template - class AnyOf : public MatcherImpl, ExpressionT> { - public: - - AnyOf() {} - AnyOf( AnyOf const& other ) : m_matchers( other.m_matchers ) {} - - AnyOf& add( Matcher const& matcher ) { - m_matchers.push_back( matcher.clone() ); - return *this; - } - virtual bool match( ExpressionT const& expr ) const - { - for( std::size_t i = 0; i < m_matchers.size(); ++i ) - if( m_matchers[i]->match( expr ) ) - return true; - return false; - } - virtual std::string toString() const { - std::ostringstream oss; - oss << "( "; - for( std::size_t i = 0; i < m_matchers.size(); ++i ) { - if( i != 0 ) - oss << " or "; - oss << m_matchers[i]->toString(); - } - oss << " )"; - return oss.str(); - } - - private: - std::vector > > m_matchers; - }; - - } - - namespace StdString { - - inline std::string makeString( std::string const& str ) { return str; } - inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); } - - struct Equals : MatcherImpl { - Equals( std::string const& str ) : m_str( str ){} - Equals( Equals const& other ) : m_str( other.m_str ){} - - virtual ~Equals(); - - virtual bool match( std::string const& expr ) const { - return m_str == expr; - } - virtual std::string toString() const { - return "equals: \"" + m_str + "\""; - } - - std::string m_str; - }; - - struct Contains : MatcherImpl { - Contains( std::string const& substr ) : m_substr( substr ){} - Contains( Contains const& other ) : m_substr( other.m_substr ){} - - virtual ~Contains(); - - virtual bool match( std::string const& expr ) const { - return expr.find( m_substr ) != std::string::npos; - } - virtual std::string toString() const { - return "contains: \"" + m_substr + "\""; - } - - std::string m_substr; - }; - - struct StartsWith : MatcherImpl { - StartsWith( std::string const& substr ) : m_substr( substr ){} - StartsWith( StartsWith const& other ) : m_substr( other.m_substr ){} - - virtual ~StartsWith(); - - virtual bool match( std::string const& expr ) const { - return expr.find( m_substr ) == 0; - } - virtual std::string toString() const { - return "starts with: \"" + m_substr + "\""; - } - - std::string m_substr; - }; - - struct EndsWith : MatcherImpl { - EndsWith( std::string const& substr ) : m_substr( substr ){} - EndsWith( EndsWith const& other ) : m_substr( other.m_substr ){} - - virtual ~EndsWith(); - - virtual bool match( std::string const& expr ) const { - return expr.find( m_substr ) == expr.size() - m_substr.size(); - } - virtual std::string toString() const { - return "ends with: \"" + m_substr + "\""; - } - - std::string m_substr; - }; - } // namespace StdString - } // namespace Impl - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - template - inline Impl::Generic::AllOf AllOf( Impl::Matcher const& m1, - Impl::Matcher const& m2 ) { - return Impl::Generic::AllOf().add( m1 ).add( m2 ); - } - template - inline Impl::Generic::AllOf AllOf( Impl::Matcher const& m1, - Impl::Matcher const& m2, - Impl::Matcher const& m3 ) { - return Impl::Generic::AllOf().add( m1 ).add( m2 ).add( m3 ); - } - template - inline Impl::Generic::AnyOf AnyOf( Impl::Matcher const& m1, - Impl::Matcher const& m2 ) { - return Impl::Generic::AnyOf().add( m1 ).add( m2 ); - } - template - inline Impl::Generic::AnyOf AnyOf( Impl::Matcher const& m1, - Impl::Matcher const& m2, - Impl::Matcher const& m3 ) { - return Impl::Generic::AnyOf().add( m1 ).add( m2 ).add( m3 ); - } - - inline Impl::StdString::Equals Equals( std::string const& str ) { - return Impl::StdString::Equals( str ); - } - inline Impl::StdString::Equals Equals( const char* str ) { - return Impl::StdString::Equals( Impl::StdString::makeString( str ) ); - } - inline Impl::StdString::Contains Contains( std::string const& substr ) { - return Impl::StdString::Contains( substr ); - } - inline Impl::StdString::Contains Contains( const char* substr ) { - return Impl::StdString::Contains( Impl::StdString::makeString( substr ) ); - } - inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) { - return Impl::StdString::StartsWith( substr ); - } - inline Impl::StdString::StartsWith StartsWith( const char* substr ) { - return Impl::StdString::StartsWith( Impl::StdString::makeString( substr ) ); - } - inline Impl::StdString::EndsWith EndsWith( std::string const& substr ) { - return Impl::StdString::EndsWith( substr ); - } - inline Impl::StdString::EndsWith EndsWith( const char* substr ) { - return Impl::StdString::EndsWith( Impl::StdString::makeString( substr ) ); - } - -} // namespace Matchers - -using namespace Matchers; - -} // namespace Catch - -// #included from: internal/catch_interfaces_tag_alias_registry.h -#define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED - -// #included from: catch_tag_alias.h -#define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED - -#include - -namespace Catch { - - struct TagAlias { - TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {} - - std::string tag; - SourceLineInfo lineInfo; - }; - - struct RegistrarForTagAliases { - RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - }; - -} // end namespace Catch - -#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } -// #included from: catch_option.hpp -#define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED - -namespace Catch { - - // An optional type - template - class Option { - public: - Option() : nullableValue( NULL ) {} - Option( T const& _value ) - : nullableValue( new( storage ) T( _value ) ) - {} - Option( Option const& _other ) - : nullableValue( _other ? new( storage ) T( *_other ) : NULL ) - {} - - ~Option() { - reset(); - } - - Option& operator= ( Option const& _other ) { - if( &_other != this ) { - reset(); - if( _other ) - nullableValue = new( storage ) T( *_other ); - } - return *this; - } - Option& operator = ( T const& _value ) { - reset(); - nullableValue = new( storage ) T( _value ); - return *this; - } - - void reset() { - if( nullableValue ) - nullableValue->~T(); - nullableValue = NULL; - } - - T& operator*() { return *nullableValue; } - T const& operator*() const { return *nullableValue; } - T* operator->() { return nullableValue; } - const T* operator->() const { return nullableValue; } - - T valueOr( T const& defaultValue ) const { - return nullableValue ? *nullableValue : defaultValue; - } - - bool some() const { return nullableValue != NULL; } - bool none() const { return nullableValue == NULL; } - - bool operator !() const { return nullableValue == NULL; } - operator SafeBool::type() const { - return SafeBool::makeSafe( some() ); - } - - private: - T* nullableValue; - char storage[sizeof(T)]; - }; - -} // end namespace Catch - -namespace Catch { - - struct ITagAliasRegistry { - virtual ~ITagAliasRegistry(); - virtual Option find( std::string const& alias ) const = 0; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; - - static ITagAliasRegistry const& get(); - }; - -} // end namespace Catch - -// These files are included here so the single_include script doesn't put them -// in the conditionally compiled sections -// #included from: internal/catch_test_case_info.h -#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED - -#include -#include - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - struct ITestCase; - - struct TestCaseInfo { - enum SpecialProperties{ - None = 0, - IsHidden = 1 << 1, - ShouldFail = 1 << 2, - MayFail = 1 << 3, - Throws = 1 << 4 - }; - - TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::set const& _tags, - SourceLineInfo const& _lineInfo ); - - TestCaseInfo( TestCaseInfo const& other ); - - bool isHidden() const; - bool throws() const; - bool okToFail() const; - bool expectedToFail() const; - - std::string name; - std::string className; - std::string description; - std::set tags; - std::set lcaseTags; - std::string tagsAsString; - SourceLineInfo lineInfo; - SpecialProperties properties; - }; - - class TestCase : public TestCaseInfo { - public: - - TestCase( ITestCase* testCase, TestCaseInfo const& info ); - TestCase( TestCase const& other ); - - TestCase withName( std::string const& _newName ) const; - - void invoke() const; - - TestCaseInfo const& getTestCaseInfo() const; - - void swap( TestCase& other ); - bool operator == ( TestCase const& other ) const; - bool operator < ( TestCase const& other ) const; - TestCase& operator = ( TestCase const& other ); - - private: - Ptr test; - }; - - TestCase makeTestCase( ITestCase* testCase, - std::string const& className, - std::string const& name, - std::string const& description, - SourceLineInfo const& lineInfo ); -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - - -#ifdef __OBJC__ -// #included from: internal/catch_objc.hpp -#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED - -#import - -#include - -// NB. Any general catch headers included here must be included -// in catch.hpp first to make sure they are included by the single -// header for non obj-usage - -/////////////////////////////////////////////////////////////////////////////// -// This protocol is really only here for (self) documenting purposes, since -// all its methods are optional. -@protocol OcFixture - -@optional - --(void) setUp; --(void) tearDown; - -@end - -namespace Catch { - - class OcMethod : public SharedImpl { - - public: - OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} - - virtual void invoke() const { - id obj = [[m_cls alloc] init]; - - performOptionalSelector( obj, @selector(setUp) ); - performOptionalSelector( obj, m_sel ); - performOptionalSelector( obj, @selector(tearDown) ); - - arcSafeRelease( obj ); - } - private: - virtual ~OcMethod() {} - - Class m_cls; - SEL m_sel; - }; - - namespace Detail{ - - inline std::string getAnnotation( Class cls, - std::string const& annotationName, - std::string const& testCaseName ) { - NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; - SEL sel = NSSelectorFromString( selStr ); - arcSafeRelease( selStr ); - id value = performOptionalSelector( cls, sel ); - if( value ) - return [(NSString*)value UTF8String]; - return ""; - } - } - - inline size_t registerTestMethods() { - size_t noTestMethods = 0; - int noClasses = objc_getClassList( NULL, 0 ); - - Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); - objc_getClassList( classes, noClasses ); - - for( int c = 0; c < noClasses; c++ ) { - Class cls = classes[c]; - { - u_int count; - Method* methods = class_copyMethodList( cls, &count ); - for( u_int m = 0; m < count ; m++ ) { - SEL selector = method_getName(methods[m]); - std::string methodName = sel_getName(selector); - if( startsWith( methodName, "Catch_TestCase_" ) ) { - std::string testCaseName = methodName.substr( 15 ); - std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); - std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); - const char* className = class_getName( cls ); - - getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) ); - noTestMethods++; - } - } - free(methods); - } - } - return noTestMethods; - } - - namespace Matchers { - namespace Impl { - namespace NSStringMatchers { - - template - struct StringHolder : MatcherImpl{ - StringHolder( NSString* substr ) : m_substr( [substr copy] ){} - StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} - StringHolder() { - arcSafeRelease( m_substr ); - } - - NSString* m_substr; - }; - - struct Equals : StringHolder { - Equals( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str isEqualToString:m_substr]; - } - - virtual std::string toString() const { - return "equals string: " + Catch::toString( m_substr ); - } - }; - - struct Contains : StringHolder { - Contains( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location != NSNotFound; - } - - virtual std::string toString() const { - return "contains string: " + Catch::toString( m_substr ); - } - }; - - struct StartsWith : StringHolder { - StartsWith( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == 0; - } - - virtual std::string toString() const { - return "starts with: " + Catch::toString( m_substr ); - } - }; - struct EndsWith : StringHolder { - EndsWith( NSString* substr ) : StringHolder( substr ){} - - virtual bool match( ExpressionType const& str ) const { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == [str length] - [m_substr length]; - } - - virtual std::string toString() const { - return "ends with: " + Catch::toString( m_substr ); - } - }; - - } // namespace NSStringMatchers - } // namespace Impl - - inline Impl::NSStringMatchers::Equals - Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } - - inline Impl::NSStringMatchers::Contains - Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } - - inline Impl::NSStringMatchers::StartsWith - StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } - - inline Impl::NSStringMatchers::EndsWith - EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } - - } // namespace Matchers - - using namespace Matchers; - -} // namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define OC_TEST_CASE( name, desc )\ -+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \ -{\ -return @ name; \ -}\ -+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \ -{ \ -return @ desc; \ -} \ --(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test ) - -#endif - -#ifdef CATCH_IMPL -// #included from: internal/catch_impl.hpp -#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED - -// Collect all the implementation files together here -// These are the equivalent of what would usually be cpp files - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wweak-vtables" -#endif - -// #included from: ../catch_runner.hpp -#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED - -// #included from: internal/catch_commandline.hpp -#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED - -// #included from: catch_config.hpp -#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED - -// #included from: catch_test_spec_parser.hpp -#define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -// #included from: catch_test_spec.hpp -#define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -#include -#include - -namespace Catch { - - class TestSpec { - struct Pattern : SharedImpl<> { - virtual ~Pattern(); - virtual bool matches( TestCaseInfo const& testCase ) const = 0; - }; - class NamePattern : public Pattern { - enum WildcardPosition { - NoWildcard = 0, - WildcardAtStart = 1, - WildcardAtEnd = 2, - WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd - }; - - public: - NamePattern( std::string const& name ) : m_name( toLower( name ) ), m_wildcard( NoWildcard ) { - if( startsWith( m_name, "*" ) ) { - m_name = m_name.substr( 1 ); - m_wildcard = WildcardAtStart; - } - if( endsWith( m_name, "*" ) ) { - m_name = m_name.substr( 0, m_name.size()-1 ); - m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); - } - } - virtual ~NamePattern(); - virtual bool matches( TestCaseInfo const& testCase ) const { - switch( m_wildcard ) { - case NoWildcard: - return m_name == toLower( testCase.name ); - case WildcardAtStart: - return endsWith( toLower( testCase.name ), m_name ); - case WildcardAtEnd: - return startsWith( toLower( testCase.name ), m_name ); - case WildcardAtBothEnds: - return contains( toLower( testCase.name ), m_name ); - } - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif - throw std::logic_error( "Unknown enum" ); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - } - private: - std::string m_name; - WildcardPosition m_wildcard; - }; - class TagPattern : public Pattern { - public: - TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} - virtual ~TagPattern(); - virtual bool matches( TestCaseInfo const& testCase ) const { - return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); - } - private: - std::string m_tag; - }; - class ExcludedPattern : public Pattern { - public: - ExcludedPattern( Ptr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} - virtual ~ExcludedPattern(); - virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } - private: - Ptr m_underlyingPattern; - }; - - struct Filter { - std::vector > m_patterns; - - bool matches( TestCaseInfo const& testCase ) const { - // All patterns in a filter must match for the filter to be a match - for( std::vector >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) - if( !(*it)->matches( testCase ) ) - return false; - return true; - } - }; - - public: - bool hasFilters() const { - return !m_filters.empty(); - } - bool matches( TestCaseInfo const& testCase ) const { - // A TestSpec matches if any filter matches - for( std::vector::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) - if( it->matches( testCase ) ) - return true; - return false; - } - - private: - std::vector m_filters; - - friend class TestSpecParser; - }; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -namespace Catch { - - class TestSpecParser { - enum Mode{ None, Name, QuotedName, Tag }; - Mode m_mode; - bool m_exclusion; - std::size_t m_start, m_pos; - std::string m_arg; - TestSpec::Filter m_currentFilter; - TestSpec m_testSpec; - ITagAliasRegistry const* m_tagAliases; - - public: - TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} - - TestSpecParser& parse( std::string const& arg ) { - m_mode = None; - m_exclusion = false; - m_start = std::string::npos; - m_arg = m_tagAliases->expandAliases( arg ); - for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) - visitChar( m_arg[m_pos] ); - if( m_mode == Name ) - addPattern(); - return *this; - } - TestSpec testSpec() { - addFilter(); - return m_testSpec; - } - private: - void visitChar( char c ) { - if( m_mode == None ) { - switch( c ) { - case ' ': return; - case '~': m_exclusion = true; return; - case '[': return startNewMode( Tag, ++m_pos ); - case '"': return startNewMode( QuotedName, ++m_pos ); - default: startNewMode( Name, m_pos ); break; - } - } - if( m_mode == Name ) { - if( c == ',' ) { - addPattern(); - addFilter(); - } - else if( c == '[' ) { - if( subString() == "exclude:" ) - m_exclusion = true; - else - addPattern(); - startNewMode( Tag, ++m_pos ); - } - } - else if( m_mode == QuotedName && c == '"' ) - addPattern(); - else if( m_mode == Tag && c == ']' ) - addPattern(); - } - void startNewMode( Mode mode, std::size_t start ) { - m_mode = mode; - m_start = start; - } - std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); } - template - void addPattern() { - std::string token = subString(); - if( startsWith( token, "exclude:" ) ) { - m_exclusion = true; - token = token.substr( 8 ); - } - if( !token.empty() ) { - Ptr pattern = new T( token ); - if( m_exclusion ) - pattern = new TestSpec::ExcludedPattern( pattern ); - m_currentFilter.m_patterns.push_back( pattern ); - } - m_exclusion = false; - m_mode = None; - } - void addFilter() { - if( !m_currentFilter.m_patterns.empty() ) { - m_testSpec.m_filters.push_back( m_currentFilter ); - m_currentFilter = TestSpec::Filter(); - } - } - }; - inline TestSpec parseTestSpec( std::string const& arg ) { - return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); - } - -} // namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// #included from: catch_interfaces_config.h -#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED - -#include -#include -#include - -namespace Catch { - - struct Verbosity { enum Level { - NoOutput = 0, - Quiet, - Normal - }; }; - - struct WarnAbout { enum What { - Nothing = 0x00, - NoAssertions = 0x01 - }; }; - - struct ShowDurations { enum OrNot { - DefaultForReporter, - Always, - Never - }; }; - struct RunTests { enum InWhatOrder { - InDeclarationOrder, - InLexicographicalOrder, - InRandomOrder - }; }; - - class TestSpec; - - struct IConfig : IShared { - - virtual ~IConfig(); - - virtual bool allowThrows() const = 0; - virtual std::ostream& stream() const = 0; - virtual std::string name() const = 0; - virtual bool includeSuccessfulResults() const = 0; - virtual bool shouldDebugBreak() const = 0; - virtual bool warnAboutMissingAssertions() const = 0; - virtual int abortAfter() const = 0; - virtual bool showInvisibles() const = 0; - virtual ShowDurations::OrNot showDurations() const = 0; - virtual TestSpec const& testSpec() const = 0; - virtual RunTests::InWhatOrder runOrder() const = 0; - virtual unsigned int rngSeed() const = 0; - virtual bool forceColour() const = 0; - }; -} - -// #included from: catch_stream.h -#define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED - -#include - -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - class Stream { - public: - Stream(); - Stream( std::streambuf* _streamBuf, bool _isOwned ); - void release(); - - std::streambuf* streamBuf; - - private: - bool isOwned; - }; - - std::ostream& cout(); - std::ostream& cerr(); -} - -#include -#include -#include -#include -#include - -#ifndef CATCH_CONFIG_CONSOLE_WIDTH -#define CATCH_CONFIG_CONSOLE_WIDTH 80 -#endif - -namespace Catch { - - struct ConfigData { - - ConfigData() - : listTests( false ), - listTags( false ), - listReporters( false ), - listTestNamesOnly( false ), - showSuccessfulTests( false ), - shouldDebugBreak( false ), - noThrow( false ), - showHelp( false ), - showInvisibles( false ), - forceColour( false ), - abortAfter( -1 ), - rngSeed( 0 ), - verbosity( Verbosity::Normal ), - warnings( WarnAbout::Nothing ), - showDurations( ShowDurations::DefaultForReporter ), - runOrder( RunTests::InDeclarationOrder ) - {} - - bool listTests; - bool listTags; - bool listReporters; - bool listTestNamesOnly; - - bool showSuccessfulTests; - bool shouldDebugBreak; - bool noThrow; - bool showHelp; - bool showInvisibles; - bool forceColour; - - int abortAfter; - unsigned int rngSeed; - - Verbosity::Level verbosity; - WarnAbout::What warnings; - ShowDurations::OrNot showDurations; - RunTests::InWhatOrder runOrder; - - std::string reporterName; - std::string outputFilename; - std::string name; - std::string processName; - - std::vector testsOrTags; - }; - - class Config : public SharedImpl { - private: - Config( Config const& other ); - Config& operator = ( Config const& other ); - virtual void dummy(); - public: - - Config() - : m_os( Catch::cout().rdbuf() ) - {} - - Config( ConfigData const& data ) - : m_data( data ), - m_os( Catch::cout().rdbuf() ) - { - if( !data.testsOrTags.empty() ) { - TestSpecParser parser( ITagAliasRegistry::get() ); - for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) - parser.parse( data.testsOrTags[i] ); - m_testSpec = parser.testSpec(); - } - } - - virtual ~Config() { - m_os.rdbuf( Catch::cout().rdbuf() ); - m_stream.release(); - } - - void setFilename( std::string const& filename ) { - m_data.outputFilename = filename; - } - - std::string const& getFilename() const { - return m_data.outputFilename ; - } - - bool listTests() const { return m_data.listTests; } - bool listTestNamesOnly() const { return m_data.listTestNamesOnly; } - bool listTags() const { return m_data.listTags; } - bool listReporters() const { return m_data.listReporters; } - - std::string getProcessName() const { return m_data.processName; } - - bool shouldDebugBreak() const { return m_data.shouldDebugBreak; } - - void setStreamBuf( std::streambuf* buf ) { - m_os.rdbuf( buf ? buf : Catch::cout().rdbuf() ); - } - - void useStream( std::string const& streamName ) { - Stream stream = createStream( streamName ); - setStreamBuf( stream.streamBuf ); - m_stream.release(); - m_stream = stream; - } - - std::string getReporterName() const { return m_data.reporterName; } - - int abortAfter() const { return m_data.abortAfter; } - - TestSpec const& testSpec() const { return m_testSpec; } - - bool showHelp() const { return m_data.showHelp; } - bool showInvisibles() const { return m_data.showInvisibles; } - - // IConfig interface - virtual bool allowThrows() const { return !m_data.noThrow; } - virtual std::ostream& stream() const { return m_os; } - virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } - virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; } - virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } - virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; } - virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; } - virtual unsigned int rngSeed() const { return m_data.rngSeed; } - virtual bool forceColour() const { return m_data.forceColour; } - - private: - ConfigData m_data; - - Stream m_stream; - mutable std::ostream m_os; - TestSpec m_testSpec; - }; - -} // end namespace Catch - -// #included from: catch_clara.h -#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED - -// Use Catch's value for console width (store Clara's off to the side, if present) -#ifdef CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH -#undef CLARA_CONFIG_CONSOLE_WIDTH -#endif -#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH - -// Declare Clara inside the Catch namespace -#define STITCH_CLARA_OPEN_NAMESPACE namespace Catch { -// #included from: ../external/clara.h - -// Only use header guard if we are not using an outer namespace -#if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE) - -#ifndef STITCH_CLARA_OPEN_NAMESPACE -#define TWOBLUECUBES_CLARA_H_INCLUDED -#define STITCH_CLARA_OPEN_NAMESPACE -#define STITCH_CLARA_CLOSE_NAMESPACE -#else -#define STITCH_CLARA_CLOSE_NAMESPACE } -#endif - -#define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE - -// ----------- #included from tbc_text_format.h ----------- - -// Only use header guard if we are not using an outer namespace -#if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE) -#ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE -#define TBC_TEXT_FORMAT_H_INCLUDED -#endif - -#include -#include -#include - -// Use optional outer namespace -#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE -namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE { -#endif - -namespace Tbc { - -#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH - const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; -#else - const unsigned int consoleWidth = 80; -#endif - - struct TextAttributes { - TextAttributes() - : initialIndent( std::string::npos ), - indent( 0 ), - width( consoleWidth-1 ), - tabChar( '\t' ) - {} - - TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } - TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } - TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } - TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } - - std::size_t initialIndent; // indent of first line, or npos - std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos - std::size_t width; // maximum width of text, including indent. Longer text will wrap - char tabChar; // If this char is seen the indent is changed to current pos - }; - - class Text { - public: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - if( lines.size() >= 1000 ) { - lines.push_back( "... message truncated due to excessive size" ); - return; - } - std::size_t tabPos = std::string::npos; - std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); - std::size_t pos = remainder.find_first_of( '\n' ); - if( pos <= width ) { - width = pos; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - - if( width == remainder.size() ) { - spliceLine( indent, remainder, width ); - } - else if( remainder[width] == '\n' ) { - spliceLine( indent, remainder, width ); - if( width <= 1 || remainder.size() != 1 ) - remainder = remainder.substr( 1 ); - indent = _attr.indent; - } - else { - pos = remainder.find_last_of( wrappableChars, width ); - if( pos != std::string::npos && pos > 0 ) { - spliceLine( indent, remainder, pos ); - if( remainder[0] == ' ' ) - remainder = remainder.substr( 1 ); - } - else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; - } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; - } - } - } - - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); - } - - typedef std::vector::const_iterator const_iterator; - - const_iterator begin() const { return lines.begin(); } - const_iterator end() const { return lines.end(); } - std::string const& last() const { return lines.back(); } - std::size_t size() const { return lines.size(); } - std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - std::string toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - - private: - std::string str; - TextAttributes attr; - std::vector lines; - }; - -} // end namespace Tbc - -#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE -} // end outer namespace -#endif - -#endif // TBC_TEXT_FORMAT_H_INCLUDED - -// ----------- end of #include from tbc_text_format.h ----------- -// ........... back in /Users/philnash/Dev/OSS/Clara/srcs/clara.h - -#undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE - -#include -#include -#include -#include - -// Use optional outer namespace -#ifdef STITCH_CLARA_OPEN_NAMESPACE -STITCH_CLARA_OPEN_NAMESPACE -#endif - -namespace Clara { - - struct UnpositionalTag {}; - - extern UnpositionalTag _; - -#ifdef CLARA_CONFIG_MAIN - UnpositionalTag _; -#endif - - namespace Detail { - -#ifdef CLARA_CONSOLE_WIDTH - const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; -#else - const unsigned int consoleWidth = 80; -#endif - - using namespace Tbc; - - inline bool startsWith( std::string const& str, std::string const& prefix ) { - return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix; - } - - template struct RemoveConstRef{ typedef T type; }; - template struct RemoveConstRef{ typedef T type; }; - template struct RemoveConstRef{ typedef T type; }; - template struct RemoveConstRef{ typedef T type; }; - - template struct IsBool { static const bool value = false; }; - template<> struct IsBool { static const bool value = true; }; - - template - void convertInto( std::string const& _source, T& _dest ) { - std::stringstream ss; - ss << _source; - ss >> _dest; - if( ss.fail() ) - throw std::runtime_error( "Unable to convert " + _source + " to destination type" ); - } - inline void convertInto( std::string const& _source, std::string& _dest ) { - _dest = _source; - } - inline void convertInto( std::string const& _source, bool& _dest ) { - std::string sourceLC = _source; - std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower ); - if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" ) - _dest = true; - else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" ) - _dest = false; - else - throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" ); - } - inline void convertInto( bool _source, bool& _dest ) { - _dest = _source; - } - template - inline void convertInto( bool, T& ) { - throw std::runtime_error( "Invalid conversion" ); - } - - template - struct IArgFunction { - virtual ~IArgFunction() {} -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - IArgFunction() = default; - IArgFunction( IArgFunction const& ) = default; -# endif - virtual void set( ConfigT& config, std::string const& value ) const = 0; - virtual void setFlag( ConfigT& config ) const = 0; - virtual bool takesArg() const = 0; - virtual IArgFunction* clone() const = 0; - }; - - template - class BoundArgFunction { - public: - BoundArgFunction() : functionObj( NULL ) {} - BoundArgFunction( IArgFunction* _functionObj ) : functionObj( _functionObj ) {} - BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : NULL ) {} - BoundArgFunction& operator = ( BoundArgFunction const& other ) { - IArgFunction* newFunctionObj = other.functionObj ? other.functionObj->clone() : NULL; - delete functionObj; - functionObj = newFunctionObj; - return *this; - } - ~BoundArgFunction() { delete functionObj; } - - void set( ConfigT& config, std::string const& value ) const { - functionObj->set( config, value ); - } - void setFlag( ConfigT& config ) const { - functionObj->setFlag( config ); - } - bool takesArg() const { return functionObj->takesArg(); } - - bool isSet() const { - return functionObj != NULL; - } - private: - IArgFunction* functionObj; - }; - - template - struct NullBinder : IArgFunction{ - virtual void set( C&, std::string const& ) const {} - virtual void setFlag( C& ) const {} - virtual bool takesArg() const { return true; } - virtual IArgFunction* clone() const { return new NullBinder( *this ); } - }; - - template - struct BoundDataMember : IArgFunction{ - BoundDataMember( M C::* _member ) : member( _member ) {} - virtual void set( C& p, std::string const& stringValue ) const { - convertInto( stringValue, p.*member ); - } - virtual void setFlag( C& p ) const { - convertInto( true, p.*member ); - } - virtual bool takesArg() const { return !IsBool::value; } - virtual IArgFunction* clone() const { return new BoundDataMember( *this ); } - M C::* member; - }; - template - struct BoundUnaryMethod : IArgFunction{ - BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {} - virtual void set( C& p, std::string const& stringValue ) const { - typename RemoveConstRef::type value; - convertInto( stringValue, value ); - (p.*member)( value ); - } - virtual void setFlag( C& p ) const { - typename RemoveConstRef::type value; - convertInto( true, value ); - (p.*member)( value ); - } - virtual bool takesArg() const { return !IsBool::value; } - virtual IArgFunction* clone() const { return new BoundUnaryMethod( *this ); } - void (C::*member)( M ); - }; - template - struct BoundNullaryMethod : IArgFunction{ - BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {} - virtual void set( C& p, std::string const& stringValue ) const { - bool value; - convertInto( stringValue, value ); - if( value ) - (p.*member)(); - } - virtual void setFlag( C& p ) const { - (p.*member)(); - } - virtual bool takesArg() const { return false; } - virtual IArgFunction* clone() const { return new BoundNullaryMethod( *this ); } - void (C::*member)(); - }; - - template - struct BoundUnaryFunction : IArgFunction{ - BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {} - virtual void set( C& obj, std::string const& stringValue ) const { - bool value; - convertInto( stringValue, value ); - if( value ) - function( obj ); - } - virtual void setFlag( C& p ) const { - function( p ); - } - virtual bool takesArg() const { return false; } - virtual IArgFunction* clone() const { return new BoundUnaryFunction( *this ); } - void (*function)( C& ); - }; - - template - struct BoundBinaryFunction : IArgFunction{ - BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {} - virtual void set( C& obj, std::string const& stringValue ) const { - typename RemoveConstRef::type value; - convertInto( stringValue, value ); - function( obj, value ); - } - virtual void setFlag( C& obj ) const { - typename RemoveConstRef::type value; - convertInto( true, value ); - function( obj, value ); - } - virtual bool takesArg() const { return !IsBool::value; } - virtual IArgFunction* clone() const { return new BoundBinaryFunction( *this ); } - void (*function)( C&, T ); - }; - - } // namespace Detail - - struct Parser { - Parser() : separators( " \t=:" ) {} - - struct Token { - enum Type { Positional, ShortOpt, LongOpt }; - Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {} - Type type; - std::string data; - }; - - void parseIntoTokens( int argc, char const * const * argv, std::vector& tokens ) const { - const std::string doubleDash = "--"; - for( int i = 1; i < argc && argv[i] != doubleDash; ++i ) - parseIntoTokens( argv[i] , tokens); - } - void parseIntoTokens( std::string arg, std::vector& tokens ) const { - while( !arg.empty() ) { - Parser::Token token( Parser::Token::Positional, arg ); - arg = ""; - if( token.data[0] == '-' ) { - if( token.data.size() > 1 && token.data[1] == '-' ) { - token = Parser::Token( Parser::Token::LongOpt, token.data.substr( 2 ) ); - } - else { - token = Parser::Token( Parser::Token::ShortOpt, token.data.substr( 1 ) ); - if( token.data.size() > 1 && separators.find( token.data[1] ) == std::string::npos ) { - arg = "-" + token.data.substr( 1 ); - token.data = token.data.substr( 0, 1 ); - } - } - } - if( token.type != Parser::Token::Positional ) { - std::size_t pos = token.data.find_first_of( separators ); - if( pos != std::string::npos ) { - arg = token.data.substr( pos+1 ); - token.data = token.data.substr( 0, pos ); - } - } - tokens.push_back( token ); - } - } - std::string separators; - }; - - template - struct CommonArgProperties { - CommonArgProperties() {} - CommonArgProperties( Detail::BoundArgFunction const& _boundField ) : boundField( _boundField ) {} - - Detail::BoundArgFunction boundField; - std::string description; - std::string detail; - std::string placeholder; // Only value if boundField takes an arg - - bool takesArg() const { - return !placeholder.empty(); - } - void validate() const { - if( !boundField.isSet() ) - throw std::logic_error( "option not bound" ); - } - }; - struct OptionArgProperties { - std::vector shortNames; - std::string longName; - - bool hasShortName( std::string const& shortName ) const { - return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end(); - } - bool hasLongName( std::string const& _longName ) const { - return _longName == longName; - } - }; - struct PositionalArgProperties { - PositionalArgProperties() : position( -1 ) {} - int position; // -1 means non-positional (floating) - - bool isFixedPositional() const { - return position != -1; - } - }; - - template - class CommandLine { - - struct Arg : CommonArgProperties, OptionArgProperties, PositionalArgProperties { - Arg() {} - Arg( Detail::BoundArgFunction const& _boundField ) : CommonArgProperties( _boundField ) {} - - using CommonArgProperties::placeholder; // !TBD - - std::string dbgName() const { - if( !longName.empty() ) - return "--" + longName; - if( !shortNames.empty() ) - return "-" + shortNames[0]; - return "positional args"; - } - std::string commands() const { - std::ostringstream oss; - bool first = true; - std::vector::const_iterator it = shortNames.begin(), itEnd = shortNames.end(); - for(; it != itEnd; ++it ) { - if( first ) - first = false; - else - oss << ", "; - oss << "-" << *it; - } - if( !longName.empty() ) { - if( !first ) - oss << ", "; - oss << "--" << longName; - } - if( !placeholder.empty() ) - oss << " <" << placeholder << ">"; - return oss.str(); - } - }; - - // NOTE: std::auto_ptr is deprecated in c++11/c++0x -#if defined(__cplusplus) && __cplusplus > 199711L - typedef std::unique_ptr ArgAutoPtr; -#else - typedef std::auto_ptr ArgAutoPtr; -#endif - - friend void addOptName( Arg& arg, std::string const& optName ) - { - if( optName.empty() ) - return; - if( Detail::startsWith( optName, "--" ) ) { - if( !arg.longName.empty() ) - throw std::logic_error( "Only one long opt may be specified. '" - + arg.longName - + "' already specified, now attempting to add '" - + optName + "'" ); - arg.longName = optName.substr( 2 ); - } - else if( Detail::startsWith( optName, "-" ) ) - arg.shortNames.push_back( optName.substr( 1 ) ); - else - throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" ); - } - friend void setPositionalArg( Arg& arg, int position ) - { - arg.position = position; - } - - class ArgBuilder { - public: - ArgBuilder( Arg* arg ) : m_arg( arg ) {} - - // Bind a non-boolean data member (requires placeholder string) - template - void bind( M C::* field, std::string const& placeholder ) { - m_arg->boundField = new Detail::BoundDataMember( field ); - m_arg->placeholder = placeholder; - } - // Bind a boolean data member (no placeholder required) - template - void bind( bool C::* field ) { - m_arg->boundField = new Detail::BoundDataMember( field ); - } - - // Bind a method taking a single, non-boolean argument (requires a placeholder string) - template - void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) { - m_arg->boundField = new Detail::BoundUnaryMethod( unaryMethod ); - m_arg->placeholder = placeholder; - } - - // Bind a method taking a single, boolean argument (no placeholder string required) - template - void bind( void (C::* unaryMethod)( bool ) ) { - m_arg->boundField = new Detail::BoundUnaryMethod( unaryMethod ); - } - - // Bind a method that takes no arguments (will be called if opt is present) - template - void bind( void (C::* nullaryMethod)() ) { - m_arg->boundField = new Detail::BoundNullaryMethod( nullaryMethod ); - } - - // Bind a free function taking a single argument - the object to operate on (no placeholder string required) - template - void bind( void (* unaryFunction)( C& ) ) { - m_arg->boundField = new Detail::BoundUnaryFunction( unaryFunction ); - } - - // Bind a free function taking a single argument - the object to operate on (requires a placeholder string) - template - void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) { - m_arg->boundField = new Detail::BoundBinaryFunction( binaryFunction ); - m_arg->placeholder = placeholder; - } - - ArgBuilder& describe( std::string const& description ) { - m_arg->description = description; - return *this; - } - ArgBuilder& detail( std::string const& detail ) { - m_arg->detail = detail; - return *this; - } - - protected: - Arg* m_arg; - }; - - class OptBuilder : public ArgBuilder { - public: - OptBuilder( Arg* arg ) : ArgBuilder( arg ) {} - OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {} - - OptBuilder& operator[]( std::string const& optName ) { - addOptName( *ArgBuilder::m_arg, optName ); - return *this; - } - }; - - public: - - CommandLine() - : m_boundProcessName( new Detail::NullBinder() ), - m_highestSpecifiedArgPosition( 0 ), - m_throwOnUnrecognisedTokens( false ) - {} - CommandLine( CommandLine const& other ) - : m_boundProcessName( other.m_boundProcessName ), - m_options ( other.m_options ), - m_positionalArgs( other.m_positionalArgs ), - m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ), - m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens ) - { - if( other.m_floatingArg.get() ) - m_floatingArg.reset( new Arg( *other.m_floatingArg ) ); - } - - CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) { - m_throwOnUnrecognisedTokens = shouldThrow; - return *this; - } - - OptBuilder operator[]( std::string const& optName ) { - m_options.push_back( Arg() ); - addOptName( m_options.back(), optName ); - OptBuilder builder( &m_options.back() ); - return builder; - } - - ArgBuilder operator[]( int position ) { - m_positionalArgs.insert( std::make_pair( position, Arg() ) ); - if( position > m_highestSpecifiedArgPosition ) - m_highestSpecifiedArgPosition = position; - setPositionalArg( m_positionalArgs[position], position ); - ArgBuilder builder( &m_positionalArgs[position] ); - return builder; - } - - // Invoke this with the _ instance - ArgBuilder operator[]( UnpositionalTag ) { - if( m_floatingArg.get() ) - throw std::logic_error( "Only one unpositional argument can be added" ); - m_floatingArg.reset( new Arg() ); - ArgBuilder builder( m_floatingArg.get() ); - return builder; - } - - template - void bindProcessName( M C::* field ) { - m_boundProcessName = new Detail::BoundDataMember( field ); - } - template - void bindProcessName( void (C::*_unaryMethod)( M ) ) { - m_boundProcessName = new Detail::BoundUnaryMethod( _unaryMethod ); - } - - void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const { - typename std::vector::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it; - std::size_t maxWidth = 0; - for( it = itBegin; it != itEnd; ++it ) - maxWidth = (std::max)( maxWidth, it->commands().size() ); - - for( it = itBegin; it != itEnd; ++it ) { - Detail::Text usage( it->commands(), Detail::TextAttributes() - .setWidth( maxWidth+indent ) - .setIndent( indent ) ); - Detail::Text desc( it->description, Detail::TextAttributes() - .setWidth( width - maxWidth - 3 ) ); - - for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) { - std::string usageCol = i < usage.size() ? usage[i] : ""; - os << usageCol; - - if( i < desc.size() && !desc[i].empty() ) - os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' ) - << desc[i]; - os << "\n"; - } - } - } - std::string optUsage() const { - std::ostringstream oss; - optUsage( oss ); - return oss.str(); - } - - void argSynopsis( std::ostream& os ) const { - for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) { - if( i > 1 ) - os << " "; - typename std::map::const_iterator it = m_positionalArgs.find( i ); - if( it != m_positionalArgs.end() ) - os << "<" << it->second.placeholder << ">"; - else if( m_floatingArg.get() ) - os << "<" << m_floatingArg->placeholder << ">"; - else - throw std::logic_error( "non consecutive positional arguments with no floating args" ); - } - // !TBD No indication of mandatory args - if( m_floatingArg.get() ) { - if( m_highestSpecifiedArgPosition > 1 ) - os << " "; - os << "[<" << m_floatingArg->placeholder << "> ...]"; - } - } - std::string argSynopsis() const { - std::ostringstream oss; - argSynopsis( oss ); - return oss.str(); - } - - void usage( std::ostream& os, std::string const& procName ) const { - validate(); - os << "usage:\n " << procName << " "; - argSynopsis( os ); - if( !m_options.empty() ) { - os << " [options]\n\nwhere options are: \n"; - optUsage( os, 2 ); - } - os << "\n"; - } - std::string usage( std::string const& procName ) const { - std::ostringstream oss; - usage( oss, procName ); - return oss.str(); - } - - ConfigT parse( int argc, char const * const * argv ) const { - ConfigT config; - parseInto( argc, argv, config ); - return config; - } - - std::vector parseInto( int argc, char const * const * argv, ConfigT& config ) const { - std::string processName = argv[0]; - std::size_t lastSlash = processName.find_last_of( "/\\" ); - if( lastSlash != std::string::npos ) - processName = processName.substr( lastSlash+1 ); - m_boundProcessName.set( config, processName ); - std::vector tokens; - Parser parser; - parser.parseIntoTokens( argc, argv, tokens ); - return populate( tokens, config ); - } - - std::vector populate( std::vector const& tokens, ConfigT& config ) const { - validate(); - std::vector unusedTokens = populateOptions( tokens, config ); - unusedTokens = populateFixedArgs( unusedTokens, config ); - unusedTokens = populateFloatingArgs( unusedTokens, config ); - return unusedTokens; - } - - std::vector populateOptions( std::vector const& tokens, ConfigT& config ) const { - std::vector unusedTokens; - std::vector errors; - for( std::size_t i = 0; i < tokens.size(); ++i ) { - Parser::Token const& token = tokens[i]; - typename std::vector::const_iterator it = m_options.begin(), itEnd = m_options.end(); - for(; it != itEnd; ++it ) { - Arg const& arg = *it; - - try { - if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) || - ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) { - if( arg.takesArg() ) { - if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional ) - errors.push_back( "Expected argument to option: " + token.data ); - else - arg.boundField.set( config, tokens[++i].data ); - } - else { - arg.boundField.setFlag( config ); - } - break; - } - } - catch( std::exception& ex ) { - errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); - } - } - if( it == itEnd ) { - if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) - unusedTokens.push_back( token ); - else if( errors.empty() && m_throwOnUnrecognisedTokens ) - errors.push_back( "unrecognised option: " + token.data ); - } - } - if( !errors.empty() ) { - std::ostringstream oss; - for( std::vector::const_iterator it = errors.begin(), itEnd = errors.end(); - it != itEnd; - ++it ) { - if( it != errors.begin() ) - oss << "\n"; - oss << *it; - } - throw std::runtime_error( oss.str() ); - } - return unusedTokens; - } - std::vector populateFixedArgs( std::vector const& tokens, ConfigT& config ) const { - std::vector unusedTokens; - int position = 1; - for( std::size_t i = 0; i < tokens.size(); ++i ) { - Parser::Token const& token = tokens[i]; - typename std::map::const_iterator it = m_positionalArgs.find( position ); - if( it != m_positionalArgs.end() ) - it->second.boundField.set( config, token.data ); - else - unusedTokens.push_back( token ); - if( token.type == Parser::Token::Positional ) - position++; - } - return unusedTokens; - } - std::vector populateFloatingArgs( std::vector const& tokens, ConfigT& config ) const { - if( !m_floatingArg.get() ) - return tokens; - std::vector unusedTokens; - for( std::size_t i = 0; i < tokens.size(); ++i ) { - Parser::Token const& token = tokens[i]; - if( token.type == Parser::Token::Positional ) - m_floatingArg->boundField.set( config, token.data ); - else - unusedTokens.push_back( token ); - } - return unusedTokens; - } - - void validate() const - { - if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() ) - throw std::logic_error( "No options or arguments specified" ); - - for( typename std::vector::const_iterator it = m_options.begin(), - itEnd = m_options.end(); - it != itEnd; ++it ) - it->validate(); - } - - private: - Detail::BoundArgFunction m_boundProcessName; - std::vector m_options; - std::map m_positionalArgs; - ArgAutoPtr m_floatingArg; - int m_highestSpecifiedArgPosition; - bool m_throwOnUnrecognisedTokens; - }; - -} // end namespace Clara - -STITCH_CLARA_CLOSE_NAMESPACE -#undef STITCH_CLARA_OPEN_NAMESPACE -#undef STITCH_CLARA_CLOSE_NAMESPACE - -#endif // TWOBLUECUBES_CLARA_H_INCLUDED -#undef STITCH_CLARA_OPEN_NAMESPACE - -// Restore Clara's value for console width, if present -#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#endif - -#include - -namespace Catch { - - inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; } - inline void abortAfterX( ConfigData& config, int x ) { - if( x < 1 ) - throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" ); - config.abortAfter = x; - } - inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); } - - inline void addWarning( ConfigData& config, std::string const& _warning ) { - if( _warning == "NoAssertions" ) - config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); - else - throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" ); - } - inline void setOrder( ConfigData& config, std::string const& order ) { - if( startsWith( "declared", order ) ) - config.runOrder = RunTests::InDeclarationOrder; - else if( startsWith( "lexical", order ) ) - config.runOrder = RunTests::InLexicographicalOrder; - else if( startsWith( "random", order ) ) - config.runOrder = RunTests::InRandomOrder; - else - throw std::runtime_error( "Unrecognised ordering: '" + order + "'" ); - } - inline void setRngSeed( ConfigData& config, std::string const& seed ) { - if( seed == "time" ) { - config.rngSeed = static_cast( std::time(0) ); - } - else { - std::stringstream ss; - ss << seed; - ss >> config.rngSeed; - if( ss.fail() ) - throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" ); - } - } - inline void setVerbosity( ConfigData& config, int level ) { - // !TBD: accept strings? - config.verbosity = static_cast( level ); - } - inline void setShowDurations( ConfigData& config, bool _showDurations ) { - config.showDurations = _showDurations - ? ShowDurations::Always - : ShowDurations::Never; - } - inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) { - std::ifstream f( _filename.c_str() ); - if( !f.is_open() ) - throw std::domain_error( "Unable to load input file: " + _filename ); - - std::string line; - while( std::getline( f, line ) ) { - line = trim(line); - if( !line.empty() && !startsWith( line, "#" ) ) - addTestOrTags( config, "\"" + line + "\"," ); - } - } - - inline Clara::CommandLine makeCommandLineParser() { - - using namespace Clara; - CommandLine cli; - - cli.bindProcessName( &ConfigData::processName ); - - cli["-?"]["-h"]["--help"] - .describe( "display usage information" ) - .bind( &ConfigData::showHelp ); - - cli["-l"]["--list-tests"] - .describe( "list all/matching test cases" ) - .bind( &ConfigData::listTests ); - - cli["-t"]["--list-tags"] - .describe( "list all/matching tags" ) - .bind( &ConfigData::listTags ); - - cli["-s"]["--success"] - .describe( "include successful tests in output" ) - .bind( &ConfigData::showSuccessfulTests ); - - cli["-b"]["--break"] - .describe( "break into debugger on failure" ) - .bind( &ConfigData::shouldDebugBreak ); - - cli["-e"]["--nothrow"] - .describe( "skip exception tests" ) - .bind( &ConfigData::noThrow ); - - cli["-i"]["--invisibles"] - .describe( "show invisibles (tabs, newlines)" ) - .bind( &ConfigData::showInvisibles ); - - cli["-o"]["--out"] - .describe( "output filename" ) - .bind( &ConfigData::outputFilename, "filename" ); - - cli["-r"]["--reporter"] -// .placeholder( "name[:filename]" ) - .describe( "reporter to use (defaults to console)" ) - .bind( &ConfigData::reporterName, "name" ); - - cli["-n"]["--name"] - .describe( "suite name" ) - .bind( &ConfigData::name, "name" ); - - cli["-a"]["--abort"] - .describe( "abort at first failure" ) - .bind( &abortAfterFirst ); - - cli["-x"]["--abortx"] - .describe( "abort after x failures" ) - .bind( &abortAfterX, "no. failures" ); - - cli["-w"]["--warn"] - .describe( "enable warnings" ) - .bind( &addWarning, "warning name" ); - -// - needs updating if reinstated -// cli.into( &setVerbosity ) -// .describe( "level of verbosity (0=no output)" ) -// .shortOpt( "v") -// .longOpt( "verbosity" ) -// .placeholder( "level" ); - - cli[_] - .describe( "which test or tests to use" ) - .bind( &addTestOrTags, "test name, pattern or tags" ); - - cli["-d"]["--durations"] - .describe( "show test durations" ) - .bind( &setShowDurations, "yes/no" ); - - cli["-f"]["--input-file"] - .describe( "load test names to run from a file" ) - .bind( &loadTestNamesFromFile, "filename" ); - - // Less common commands which don't have a short form - cli["--list-test-names-only"] - .describe( "list all/matching test cases names only" ) - .bind( &ConfigData::listTestNamesOnly ); - - cli["--list-reporters"] - .describe( "list all reporters" ) - .bind( &ConfigData::listReporters ); - - cli["--order"] - .describe( "test case order (defaults to decl)" ) - .bind( &setOrder, "decl|lex|rand" ); - - cli["--rng-seed"] - .describe( "set a specific seed for random numbers" ) - .bind( &setRngSeed, "'time'|number" ); - - cli["--force-colour"] - .describe( "force colourised output" ) - .bind( &ConfigData::forceColour ); - - return cli; - } - -} // end namespace Catch - -// #included from: internal/catch_list.hpp -#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED - -// #included from: catch_text.h -#define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED - -#define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH - -#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch -// #included from: ../external/tbc_text_format.h -// Only use header guard if we are not using an outer namespace -#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE -# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED -# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -# endif -# else -# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED -# endif -#endif -#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -#include -#include -#include - -// Use optional outer namespace -#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE -namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { -#endif - -namespace Tbc { - -#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH - const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; -#else - const unsigned int consoleWidth = 80; -#endif - - struct TextAttributes { - TextAttributes() - : initialIndent( std::string::npos ), - indent( 0 ), - width( consoleWidth-1 ), - tabChar( '\t' ) - {} - - TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } - TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } - TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } - TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } - - std::size_t initialIndent; // indent of first line, or npos - std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos - std::size_t width; // maximum width of text, including indent. Longer text will wrap - char tabChar; // If this char is seen the indent is changed to current pos - }; - - class Text { - public: - Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) - : attr( _attr ) - { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; - - while( !remainder.empty() ) { - if( lines.size() >= 1000 ) { - lines.push_back( "... message truncated due to excessive size" ); - return; - } - std::size_t tabPos = std::string::npos; - std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); - std::size_t pos = remainder.find_first_of( '\n' ); - if( pos <= width ) { - width = pos; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - - if( width == remainder.size() ) { - spliceLine( indent, remainder, width ); - } - else if( remainder[width] == '\n' ) { - spliceLine( indent, remainder, width ); - if( width <= 1 || remainder.size() != 1 ) - remainder = remainder.substr( 1 ); - indent = _attr.indent; - } - else { - pos = remainder.find_last_of( wrappableChars, width ); - if( pos != std::string::npos && pos > 0 ) { - spliceLine( indent, remainder, pos ); - if( remainder[0] == ' ' ) - remainder = remainder.substr( 1 ); - } - else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; - } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; - } - } - } - - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); - } - - typedef std::vector::const_iterator const_iterator; - - const_iterator begin() const { return lines.begin(); } - const_iterator end() const { return lines.end(); } - std::string const& last() const { return lines.back(); } - std::size_t size() const { return lines.size(); } - std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } - std::string toString() const { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - - inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { - for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); - it != itEnd; ++it ) { - if( it != _text.begin() ) - _stream << "\n"; - _stream << *it; - } - return _stream; - } - - private: - std::string str; - TextAttributes attr; - std::vector lines; - }; - -} // end namespace Tbc - -#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE -} // end outer namespace -#endif - -#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED -#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE - -namespace Catch { - using Tbc::Text; - using Tbc::TextAttributes; -} - -// #included from: catch_console_colour.hpp -#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED - -namespace Catch { - - struct Colour { - enum Code { - None = 0, - - White, - Red, - Green, - Blue, - Cyan, - Yellow, - Grey, - - Bright = 0x10, - - BrightRed = Bright | Red, - BrightGreen = Bright | Green, - LightGrey = Bright | Grey, - BrightWhite = Bright | White, - - // By intention - FileName = LightGrey, - Warning = Yellow, - ResultError = BrightRed, - ResultSuccess = BrightGreen, - ResultExpectedFailure = Warning, - - Error = BrightRed, - Success = Green, - - OriginalExpression = Cyan, - ReconstructedExpression = Yellow, - - SecondaryText = LightGrey, - Headers = White - }; - - // Use constructed object for RAII guard - Colour( Code _colourCode ); - Colour( Colour const& other ); - ~Colour(); - - // Use static method for one-shot changes - static void use( Code _colourCode ); - - private: - bool m_moved; - }; - - inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; } - -} // end namespace Catch - -// #included from: catch_interfaces_reporter.h -#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED - -#include -#include -#include -#include - -namespace Catch -{ - struct ReporterConfig { - explicit ReporterConfig( Ptr const& _fullConfig ) - : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} - - ReporterConfig( Ptr const& _fullConfig, std::ostream& _stream ) - : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} - - std::ostream& stream() const { return *m_stream; } - Ptr fullConfig() const { return m_fullConfig; } - - private: - std::ostream* m_stream; - Ptr m_fullConfig; - }; - - struct ReporterPreferences { - ReporterPreferences() - : shouldRedirectStdOut( false ) - {} - - bool shouldRedirectStdOut; - }; - - template - struct LazyStat : Option { - LazyStat() : used( false ) {} - LazyStat& operator=( T const& _value ) { - Option::operator=( _value ); - used = false; - return *this; - } - void reset() { - Option::reset(); - used = false; - } - bool used; - }; - - struct TestRunInfo { - TestRunInfo( std::string const& _name ) : name( _name ) {} - std::string name; - }; - struct GroupInfo { - GroupInfo( std::string const& _name, - std::size_t _groupIndex, - std::size_t _groupsCount ) - : name( _name ), - groupIndex( _groupIndex ), - groupsCounts( _groupsCount ) - {} - - std::string name; - std::size_t groupIndex; - std::size_t groupsCounts; - }; - - struct AssertionStats { - AssertionStats( AssertionResult const& _assertionResult, - std::vector const& _infoMessages, - Totals const& _totals ) - : assertionResult( _assertionResult ), - infoMessages( _infoMessages ), - totals( _totals ) - { - if( assertionResult.hasMessage() ) { - // Copy message into messages list. - // !TBD This should have been done earlier, somewhere - MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); - builder << assertionResult.getMessage(); - builder.m_info.message = builder.m_stream.str(); - - infoMessages.push_back( builder.m_info ); - } - } - virtual ~AssertionStats(); - -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - AssertionStats( AssertionStats const& ) = default; - AssertionStats( AssertionStats && ) = default; - AssertionStats& operator = ( AssertionStats const& ) = default; - AssertionStats& operator = ( AssertionStats && ) = default; -# endif - - AssertionResult assertionResult; - std::vector infoMessages; - Totals totals; - }; - - struct SectionStats { - SectionStats( SectionInfo const& _sectionInfo, - Counts const& _assertions, - double _durationInSeconds, - bool _missingAssertions ) - : sectionInfo( _sectionInfo ), - assertions( _assertions ), - durationInSeconds( _durationInSeconds ), - missingAssertions( _missingAssertions ) - {} - virtual ~SectionStats(); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - SectionStats( SectionStats const& ) = default; - SectionStats( SectionStats && ) = default; - SectionStats& operator = ( SectionStats const& ) = default; - SectionStats& operator = ( SectionStats && ) = default; -# endif - - SectionInfo sectionInfo; - Counts assertions; - double durationInSeconds; - bool missingAssertions; - }; - - struct TestCaseStats { - TestCaseStats( TestCaseInfo const& _testInfo, - Totals const& _totals, - std::string const& _stdOut, - std::string const& _stdErr, - bool _aborting ) - : testInfo( _testInfo ), - totals( _totals ), - stdOut( _stdOut ), - stdErr( _stdErr ), - aborting( _aborting ) - {} - virtual ~TestCaseStats(); - -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - TestCaseStats( TestCaseStats const& ) = default; - TestCaseStats( TestCaseStats && ) = default; - TestCaseStats& operator = ( TestCaseStats const& ) = default; - TestCaseStats& operator = ( TestCaseStats && ) = default; -# endif - - TestCaseInfo testInfo; - Totals totals; - std::string stdOut; - std::string stdErr; - bool aborting; - }; - - struct TestGroupStats { - TestGroupStats( GroupInfo const& _groupInfo, - Totals const& _totals, - bool _aborting ) - : groupInfo( _groupInfo ), - totals( _totals ), - aborting( _aborting ) - {} - TestGroupStats( GroupInfo const& _groupInfo ) - : groupInfo( _groupInfo ), - aborting( false ) - {} - virtual ~TestGroupStats(); - -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - TestGroupStats( TestGroupStats const& ) = default; - TestGroupStats( TestGroupStats && ) = default; - TestGroupStats& operator = ( TestGroupStats const& ) = default; - TestGroupStats& operator = ( TestGroupStats && ) = default; -# endif - - GroupInfo groupInfo; - Totals totals; - bool aborting; - }; - - struct TestRunStats { - TestRunStats( TestRunInfo const& _runInfo, - Totals const& _totals, - bool _aborting ) - : runInfo( _runInfo ), - totals( _totals ), - aborting( _aborting ) - {} - virtual ~TestRunStats(); - -# ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS - TestRunStats( TestRunStats const& _other ) - : runInfo( _other.runInfo ), - totals( _other.totals ), - aborting( _other.aborting ) - {} -# else - TestRunStats( TestRunStats const& ) = default; - TestRunStats( TestRunStats && ) = default; - TestRunStats& operator = ( TestRunStats const& ) = default; - TestRunStats& operator = ( TestRunStats && ) = default; -# endif - - TestRunInfo runInfo; - Totals totals; - bool aborting; - }; - - struct IStreamingReporter : IShared { - virtual ~IStreamingReporter(); - - // Implementing class must also provide the following static method: - // static std::string getDescription(); - - virtual ReporterPreferences getPreferences() const = 0; - - virtual void noMatchingTestCases( std::string const& spec ) = 0; - - virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; - virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; - - virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; - virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; - - virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; - - // The return value indicates if the messages buffer should be cleared: - virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; - virtual void sectionEnded( SectionStats const& sectionStats ) = 0; - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; - virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; - - virtual void skipTest( TestCaseInfo const& testInfo ) = 0; - }; - - struct IReporterFactory { - virtual ~IReporterFactory(); - virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0; - virtual std::string getDescription() const = 0; - }; - - struct IReporterRegistry { - typedef std::map FactoryMap; - - virtual ~IReporterRegistry(); - virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const = 0; - virtual FactoryMap const& getFactories() const = 0; - }; - -} - -#include -#include - -namespace Catch { - - inline std::size_t listTests( Config const& config ) { - - TestSpec testSpec = config.testSpec(); - if( config.testSpec().hasFilters() ) - Catch::cout() << "Matching test cases:\n"; - else { - Catch::cout() << "All available test cases:\n"; - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); - } - - std::size_t matchedTests = 0; - TextAttributes nameAttr, tagsAttr; - nameAttr.setInitialIndent( 2 ).setIndent( 4 ); - tagsAttr.setIndent( 6 ); - - std::vector matchedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - matchedTests++; - TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); - Colour::Code colour = testCaseInfo.isHidden() - ? Colour::SecondaryText - : Colour::None; - Colour colourGuard( colour ); - - Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; - if( !testCaseInfo.tags.empty() ) - Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; - } - - if( !config.testSpec().hasFilters() ) - Catch::cout() << pluralise( matchedTests, "test case" ) << "\n" << std::endl; - else - Catch::cout() << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl; - return matchedTests; - } - - inline std::size_t listTestsNamesOnly( Config const& config ) { - TestSpec testSpec = config.testSpec(); - if( !config.testSpec().hasFilters() ) - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); - std::size_t matchedTests = 0; - std::vector matchedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - matchedTests++; - TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); - Catch::cout() << testCaseInfo.name << std::endl; - } - return matchedTests; - } - - struct TagInfo { - TagInfo() : count ( 0 ) {} - void add( std::string const& spelling ) { - ++count; - spellings.insert( spelling ); - } - std::string all() const { - std::string out; - for( std::set::const_iterator it = spellings.begin(), itEnd = spellings.end(); - it != itEnd; - ++it ) - out += "[" + *it + "]"; - return out; - } - std::set spellings; - std::size_t count; - }; - - inline std::size_t listTags( Config const& config ) { - TestSpec testSpec = config.testSpec(); - if( config.testSpec().hasFilters() ) - Catch::cout() << "Tags for matching test cases:\n"; - else { - Catch::cout() << "All available tags:\n"; - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); - } - - std::map tagCounts; - - std::vector matchedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - for( std::set::const_iterator tagIt = it->getTestCaseInfo().tags.begin(), - tagItEnd = it->getTestCaseInfo().tags.end(); - tagIt != tagItEnd; - ++tagIt ) { - std::string tagName = *tagIt; - std::string lcaseTagName = toLower( tagName ); - std::map::iterator countIt = tagCounts.find( lcaseTagName ); - if( countIt == tagCounts.end() ) - countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; - countIt->second.add( tagName ); - } - } - - for( std::map::const_iterator countIt = tagCounts.begin(), - countItEnd = tagCounts.end(); - countIt != countItEnd; - ++countIt ) { - std::ostringstream oss; - oss << " " << std::setw(2) << countIt->second.count << " "; - Text wrapper( countIt->second.all(), TextAttributes() - .setInitialIndent( 0 ) - .setIndent( oss.str().size() ) - .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); - Catch::cout() << oss.str() << wrapper << "\n"; - } - Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl; - return tagCounts.size(); - } - - inline std::size_t listReporters( Config const& /*config*/ ) { - Catch::cout() << "Available reporters:\n"; - IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); - IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it; - std::size_t maxNameLen = 0; - for(it = itBegin; it != itEnd; ++it ) - maxNameLen = (std::max)( maxNameLen, it->first.size() ); - - for(it = itBegin; it != itEnd; ++it ) { - Text wrapper( it->second->getDescription(), TextAttributes() - .setInitialIndent( 0 ) - .setIndent( 7+maxNameLen ) - .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); - Catch::cout() << " " - << it->first - << ":" - << std::string( maxNameLen - it->first.size() + 2, ' ' ) - << wrapper << "\n"; - } - Catch::cout() << std::endl; - return factories.size(); - } - - inline Option list( Config const& config ) { - Option listedCount; - if( config.listTests() ) - listedCount = listedCount.valueOr(0) + listTests( config ); - if( config.listTestNamesOnly() ) - listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); - if( config.listTags() ) - listedCount = listedCount.valueOr(0) + listTags( config ); - if( config.listReporters() ) - listedCount = listedCount.valueOr(0) + listReporters( config ); - return listedCount; - } - -} // end namespace Catch - -// #included from: internal/catch_runner_impl.hpp -#define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED - -// #included from: catch_test_case_tracker.hpp -#define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED - -#include -#include -#include - -namespace Catch { -namespace SectionTracking { - - class TrackedSection { - - typedef std::map TrackedSections; - - public: - enum RunState { - NotStarted, - Executing, - ExecutingChildren, - Completed - }; - - TrackedSection( std::string const& name, TrackedSection* parent ) - : m_name( name ), m_runState( NotStarted ), m_parent( parent ) - {} - - RunState runState() const { return m_runState; } - - TrackedSection* findChild( std::string const& childName ); - TrackedSection* acquireChild( std::string const& childName ); - - void enter() { - if( m_runState == NotStarted ) - m_runState = Executing; - } - void leave(); - - TrackedSection* getParent() { - return m_parent; - } - bool hasChildren() const { - return !m_children.empty(); - } - - private: - std::string m_name; - RunState m_runState; - TrackedSections m_children; - TrackedSection* m_parent; - }; - - inline TrackedSection* TrackedSection::findChild( std::string const& childName ) { - TrackedSections::iterator it = m_children.find( childName ); - return it != m_children.end() - ? &it->second - : NULL; - } - inline TrackedSection* TrackedSection::acquireChild( std::string const& childName ) { - if( TrackedSection* child = findChild( childName ) ) - return child; - m_children.insert( std::make_pair( childName, TrackedSection( childName, this ) ) ); - return findChild( childName ); - } - inline void TrackedSection::leave() { - for( TrackedSections::const_iterator it = m_children.begin(), itEnd = m_children.end(); - it != itEnd; - ++it ) - if( it->second.runState() != Completed ) { - m_runState = ExecutingChildren; - return; - } - m_runState = Completed; - } - - class TestCaseTracker { - public: - TestCaseTracker( std::string const& testCaseName ) - : m_testCase( testCaseName, NULL ), - m_currentSection( &m_testCase ), - m_completedASectionThisRun( false ) - {} - - bool enterSection( std::string const& name ) { - TrackedSection* child = m_currentSection->acquireChild( name ); - if( m_completedASectionThisRun || child->runState() == TrackedSection::Completed ) - return false; - - m_currentSection = child; - m_currentSection->enter(); - return true; - } - void leaveSection() { - m_currentSection->leave(); - m_currentSection = m_currentSection->getParent(); - assert( m_currentSection != NULL ); - m_completedASectionThisRun = true; - } - - bool currentSectionHasChildren() const { - return m_currentSection->hasChildren(); - } - bool isCompleted() const { - return m_testCase.runState() == TrackedSection::Completed; - } - - class Guard { - public: - Guard( TestCaseTracker& tracker ) : m_tracker( tracker ) { - m_tracker.enterTestCase(); - } - ~Guard() { - m_tracker.leaveTestCase(); - } - private: - Guard( Guard const& ); - void operator = ( Guard const& ); - TestCaseTracker& m_tracker; - }; - - private: - void enterTestCase() { - m_currentSection = &m_testCase; - m_completedASectionThisRun = false; - m_testCase.enter(); - } - void leaveTestCase() { - m_testCase.leave(); - } - - TrackedSection m_testCase; - TrackedSection* m_currentSection; - bool m_completedASectionThisRun; - }; - -} // namespace SectionTracking - -using SectionTracking::TestCaseTracker; - -} // namespace Catch - -// #included from: catch_fatal_condition.hpp -#define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED - -namespace Catch { - - // Report the error condition then exit the process - inline void fatal( std::string const& message, int exitCode ) { - IContext& context = Catch::getCurrentContext(); - IResultCapture* resultCapture = context.getResultCapture(); - resultCapture->handleFatalErrorCondition( message ); - - if( Catch::alwaysTrue() ) // avoids "no return" warnings - exit( exitCode ); - } - -} // namespace Catch - -#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// - -namespace Catch { - - struct FatalConditionHandler { - void reset() {} - }; - -} // namespace Catch - -#else // Not Windows - assumed to be POSIX compatible ////////////////////////// - -#include - -namespace Catch { - - struct SignalDefs { int id; const char* name; }; - extern SignalDefs signalDefs[]; - SignalDefs signalDefs[] = { - { SIGINT, "SIGINT - Terminal interrupt signal" }, - { SIGILL, "SIGILL - Illegal instruction signal" }, - { SIGFPE, "SIGFPE - Floating point error signal" }, - { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, - { SIGTERM, "SIGTERM - Termination request signal" }, - { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } - }; - - struct FatalConditionHandler { - - static void handleSignal( int sig ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - if( sig == signalDefs[i].id ) - fatal( signalDefs[i].name, -sig ); - fatal( "", -sig ); - } - - FatalConditionHandler() : m_isSet( true ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - signal( signalDefs[i].id, handleSignal ); - } - ~FatalConditionHandler() { - reset(); - } - void reset() { - if( m_isSet ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - signal( signalDefs[i].id, SIG_DFL ); - m_isSet = false; - } - } - - bool m_isSet; - }; - -} // namespace Catch - -#endif // not Windows - -#include -#include - -namespace Catch { - - class StreamRedirect { - - public: - StreamRedirect( std::ostream& stream, std::string& targetString ) - : m_stream( stream ), - m_prevBuf( stream.rdbuf() ), - m_targetString( targetString ) - { - stream.rdbuf( m_oss.rdbuf() ); - } - - ~StreamRedirect() { - m_targetString += m_oss.str(); - m_stream.rdbuf( m_prevBuf ); - } - - private: - std::ostream& m_stream; - std::streambuf* m_prevBuf; - std::ostringstream m_oss; - std::string& m_targetString; - }; - - /////////////////////////////////////////////////////////////////////////// - - class RunContext : public IResultCapture, public IRunner { - - RunContext( RunContext const& ); - void operator =( RunContext const& ); - - public: - - explicit RunContext( Ptr const& config, Ptr const& reporter ) - : m_runInfo( config->name() ), - m_context( getCurrentMutableContext() ), - m_activeTestCase( NULL ), - m_config( config ), - m_reporter( reporter ), - m_prevRunner( m_context.getRunner() ), - m_prevResultCapture( m_context.getResultCapture() ), - m_prevConfig( m_context.getConfig() ) - { - m_context.setRunner( this ); - m_context.setConfig( m_config ); - m_context.setResultCapture( this ); - m_reporter->testRunStarting( m_runInfo ); - } - - virtual ~RunContext() { - m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); - m_context.setRunner( m_prevRunner ); - m_context.setConfig( NULL ); - m_context.setResultCapture( m_prevResultCapture ); - m_context.setConfig( m_prevConfig ); - } - - void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) { - m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) ); - } - void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) { - m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) ); - } - - Totals runTest( TestCase const& testCase ) { - Totals prevTotals = m_totals; - - std::string redirectedCout; - std::string redirectedCerr; - - TestCaseInfo testInfo = testCase.getTestCaseInfo(); - - m_reporter->testCaseStarting( testInfo ); - - m_activeTestCase = &testCase; - m_testCaseTracker = TestCaseTracker( testInfo.name ); - - do { - do { - runCurrentTest( redirectedCout, redirectedCerr ); - } - while( !m_testCaseTracker->isCompleted() && !aborting() ); - } - while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); - - Totals deltaTotals = m_totals.delta( prevTotals ); - m_totals.testCases += deltaTotals.testCases; - m_reporter->testCaseEnded( TestCaseStats( testInfo, - deltaTotals, - redirectedCout, - redirectedCerr, - aborting() ) ); - - m_activeTestCase = NULL; - m_testCaseTracker.reset(); - - return deltaTotals; - } - - Ptr config() const { - return m_config; - } - - private: // IResultCapture - - virtual void assertionEnded( AssertionResult const& result ) { - if( result.getResultType() == ResultWas::Ok ) { - m_totals.assertions.passed++; - } - else if( !result.isOk() ) { - m_totals.assertions.failed++; - } - - if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) ) - m_messages.clear(); - - // Reset working state - m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); - m_lastResult = result; - } - - virtual bool sectionStarted ( - SectionInfo const& sectionInfo, - Counts& assertions - ) - { - std::ostringstream oss; - oss << sectionInfo.name << "@" << sectionInfo.lineInfo; - - if( !m_testCaseTracker->enterSection( oss.str() ) ) - return false; - - m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; - - m_reporter->sectionStarting( sectionInfo ); - - assertions = m_totals.assertions; - - return true; - } - bool testForMissingAssertions( Counts& assertions ) { - if( assertions.total() != 0 || - !m_config->warnAboutMissingAssertions() || - m_testCaseTracker->currentSectionHasChildren() ) - return false; - m_totals.assertions.failed++; - assertions.failed++; - return true; - } - - virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions, double _durationInSeconds ) { - if( std::uncaught_exception() ) { - m_unfinishedSections.push_back( UnfinishedSections( info, prevAssertions, _durationInSeconds ) ); - return; - } - - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions( assertions ); - - m_testCaseTracker->leaveSection(); - - m_reporter->sectionEnded( SectionStats( info, assertions, _durationInSeconds, missingAssertions ) ); - m_messages.clear(); - } - - virtual void pushScopedMessage( MessageInfo const& message ) { - m_messages.push_back( message ); - } - - virtual void popScopedMessage( MessageInfo const& message ) { - m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() ); - } - - virtual std::string getCurrentTestName() const { - return m_activeTestCase - ? m_activeTestCase->getTestCaseInfo().name - : ""; - } - - virtual const AssertionResult* getLastResult() const { - return &m_lastResult; - } - - virtual void handleFatalErrorCondition( std::string const& message ) { - ResultBuilder resultBuilder = makeUnexpectedResultBuilder(); - resultBuilder.setResultType( ResultWas::FatalErrorCondition ); - resultBuilder << message; - resultBuilder.captureExpression(); - - handleUnfinishedSections(); - - // Recreate section for test case (as we will lose the one that was in scope) - TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); - - Counts assertions; - assertions.failed = 1; - SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false ); - m_reporter->sectionEnded( testCaseSectionStats ); - - TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo(); - - Totals deltaTotals; - deltaTotals.testCases.failed = 1; - m_reporter->testCaseEnded( TestCaseStats( testInfo, - deltaTotals, - "", - "", - false ) ); - m_totals.testCases.failed++; - testGroupEnded( "", m_totals, 1, 1 ); - m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) ); - } - - public: - // !TBD We need to do this another way! - bool aborting() const { - return m_totals.assertions.failed == static_cast( m_config->abortAfter() ); - } - - private: - - void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) { - TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); - m_reporter->sectionStarting( testCaseSection ); - Counts prevAssertions = m_totals.assertions; - double duration = 0; - try { - m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); - TestCaseTracker::Guard guard( *m_testCaseTracker ); - - Timer timer; - timer.start(); - if( m_reporter->getPreferences().shouldRedirectStdOut ) { - StreamRedirect coutRedir( Catch::cout(), redirectedCout ); - StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr ); - invokeActiveTestCase(); - } - else { - invokeActiveTestCase(); - } - duration = timer.getElapsedSeconds(); - } - catch( TestFailureException& ) { - // This just means the test was aborted due to failure - } - catch(...) { - makeUnexpectedResultBuilder().useActiveException(); - } - handleUnfinishedSections(); - m_messages.clear(); - - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions( assertions ); - - if( testCaseInfo.okToFail() ) { - std::swap( assertions.failedButOk, assertions.failed ); - m_totals.assertions.failed -= assertions.failedButOk; - m_totals.assertions.failedButOk += assertions.failedButOk; - } - - SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions ); - m_reporter->sectionEnded( testCaseSectionStats ); - } - - void invokeActiveTestCase() { - FatalConditionHandler fatalConditionHandler; // Handle signals - m_activeTestCase->invoke(); - fatalConditionHandler.reset(); - } - - private: - - ResultBuilder makeUnexpectedResultBuilder() const { - return ResultBuilder( m_lastAssertionInfo.macroName.c_str(), - m_lastAssertionInfo.lineInfo, - m_lastAssertionInfo.capturedExpression.c_str(), - m_lastAssertionInfo.resultDisposition ); - } - - void handleUnfinishedSections() { - // If sections ended prematurely due to an exception we stored their - // infos here so we can tear them down outside the unwind process. - for( std::vector::const_reverse_iterator it = m_unfinishedSections.rbegin(), - itEnd = m_unfinishedSections.rend(); - it != itEnd; - ++it ) - sectionEnded( it->info, it->prevAssertions, it->durationInSeconds ); - m_unfinishedSections.clear(); - } - - struct UnfinishedSections { - UnfinishedSections( SectionInfo const& _info, Counts const& _prevAssertions, double _durationInSeconds ) - : info( _info ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) - {} - - SectionInfo info; - Counts prevAssertions; - double durationInSeconds; - }; - - TestRunInfo m_runInfo; - IMutableContext& m_context; - TestCase const* m_activeTestCase; - Option m_testCaseTracker; - AssertionResult m_lastResult; - - Ptr m_config; - Totals m_totals; - Ptr m_reporter; - std::vector m_messages; - IRunner* m_prevRunner; - IResultCapture* m_prevResultCapture; - Ptr m_prevConfig; - AssertionInfo m_lastAssertionInfo; - std::vector m_unfinishedSections; - }; - - IResultCapture& getResultCapture() { - if( IResultCapture* capture = getCurrentContext().getResultCapture() ) - return *capture; - else - throw std::logic_error( "No result capture instance" ); - } - -} // end namespace Catch - -// #included from: internal/catch_version.h -#define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED - -namespace Catch { - - // Versioning information - struct Version { - Version( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - std::string const& _branchName, - unsigned int _buildNumber ); - - unsigned int const majorVersion; - unsigned int const minorVersion; - unsigned int const patchNumber; - - // buildNumber is only used if branchName is not null - std::string const branchName; - unsigned int const buildNumber; - - friend std::ostream& operator << ( std::ostream& os, Version const& version ); - - private: - void operator=( Version const& ); - }; - - extern Version libraryVersion; -} - -#include -#include -#include - -namespace Catch { - - class Runner { - - public: - Runner( Ptr const& config ) - : m_config( config ) - { - openStream(); - makeReporter(); - } - - Totals runTests() { - - RunContext context( m_config.get(), m_reporter ); - - Totals totals; - - context.testGroupStarting( "all tests", 1, 1 ); // deprecated? - - TestSpec testSpec = m_config->testSpec(); - if( !testSpec.hasFilters() ) - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests - - std::vector testCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, testCases ); - - int testsRunForGroup = 0; - for( std::vector::const_iterator it = testCases.begin(), itEnd = testCases.end(); - it != itEnd; - ++it ) { - testsRunForGroup++; - if( m_testsAlreadyRun.find( *it ) == m_testsAlreadyRun.end() ) { - - if( context.aborting() ) - break; - - totals += context.runTest( *it ); - m_testsAlreadyRun.insert( *it ); - } - } - std::vector skippedTestCases; - getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true ); - - for( std::vector::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end(); - it != itEnd; - ++it ) - m_reporter->skipTest( *it ); - - context.testGroupEnded( "all tests", totals, 1, 1 ); - return totals; - } - - private: - void openStream() { - // Open output file, if specified - if( !m_config->getFilename().empty() ) { - m_ofs.open( m_config->getFilename().c_str() ); - if( m_ofs.fail() ) { - std::ostringstream oss; - oss << "Unable to open file: '" << m_config->getFilename() << "'"; - throw std::domain_error( oss.str() ); - } - m_config->setStreamBuf( m_ofs.rdbuf() ); - } - } - void makeReporter() { - std::string reporterName = m_config->getReporterName().empty() - ? "console" - : m_config->getReporterName(); - - m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, m_config.get() ); - if( !m_reporter ) { - std::ostringstream oss; - oss << "No reporter registered with name: '" << reporterName << "'"; - throw std::domain_error( oss.str() ); - } - } - - private: - Ptr m_config; - std::ofstream m_ofs; - Ptr m_reporter; - std::set m_testsAlreadyRun; - }; - - class Session : NonCopyable { - static bool alreadyInstantiated; - - public: - - struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; }; - - Session() - : m_cli( makeCommandLineParser() ) { - if( alreadyInstantiated ) { - std::string msg = "Only one instance of Catch::Session can ever be used"; - Catch::cerr() << msg << std::endl; - throw std::logic_error( msg ); - } - alreadyInstantiated = true; - } - ~Session() { - Catch::cleanUp(); - } - - void showHelp( std::string const& processName ) { - Catch::cout() << "\nCatch v" << libraryVersion << "\n"; - - m_cli.usage( Catch::cout(), processName ); - Catch::cout() << "For more detail usage please see the project docs\n" << std::endl; - } - - int applyCommandLine( int argc, char* const argv[], OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) { - try { - m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail ); - m_unusedTokens = m_cli.parseInto( argc, argv, m_configData ); - if( m_configData.showHelp ) - showHelp( m_configData.processName ); - m_config.reset(); - } - catch( std::exception& ex ) { - { - Colour colourGuard( Colour::Red ); - Catch::cerr() - << "\nError(s) in input:\n" - << Text( ex.what(), TextAttributes().setIndent(2) ) - << "\n\n"; - } - m_cli.usage( Catch::cout(), m_configData.processName ); - return (std::numeric_limits::max)(); - } - return 0; - } - - void useConfigData( ConfigData const& _configData ) { - m_configData = _configData; - m_config.reset(); - } - - int run( int argc, char* const argv[] ) { - - int returnCode = applyCommandLine( argc, argv ); - if( returnCode == 0 ) - returnCode = run(); - return returnCode; - } - - int run() { - if( m_configData.showHelp ) - return 0; - - try - { - config(); // Force config to be constructed - - std::srand( m_configData.rngSeed ); - - Runner runner( m_config ); - - // Handle list request - if( Option listed = list( config() ) ) - return static_cast( *listed ); - - return static_cast( runner.runTests().assertions.failed ); - } - catch( std::exception& ex ) { - Catch::cerr() << ex.what() << std::endl; - return (std::numeric_limits::max)(); - } - } - - Clara::CommandLine const& cli() const { - return m_cli; - } - std::vector const& unusedTokens() const { - return m_unusedTokens; - } - ConfigData& configData() { - return m_configData; - } - Config& config() { - if( !m_config ) - m_config = new Config( m_configData ); - return *m_config; - } - - private: - Clara::CommandLine m_cli; - std::vector m_unusedTokens; - ConfigData m_configData; - Ptr m_config; - }; - - bool Session::alreadyInstantiated = false; - -} // end namespace Catch - -// #included from: catch_registry_hub.hpp -#define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED - -// #included from: catch_test_case_registry_impl.hpp -#define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace Catch { - - class TestRegistry : public ITestCaseRegistry { - struct LexSort { - bool operator() (TestCase i,TestCase j) const { return (i const& getAllTests() const { - return m_functionsInOrder; - } - - virtual std::vector const& getAllNonHiddenTests() const { - return m_nonHiddenFunctions; - } - - virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector& matchingTestCases, bool negated = false ) const { - - for( std::vector::const_iterator it = m_functionsInOrder.begin(), - itEnd = m_functionsInOrder.end(); - it != itEnd; - ++it ) { - bool includeTest = testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ); - if( includeTest != negated ) - matchingTestCases.push_back( *it ); - } - sortTests( config, matchingTestCases ); - } - - private: - - static void sortTests( IConfig const& config, std::vector& matchingTestCases ) { - - switch( config.runOrder() ) { - case RunTests::InLexicographicalOrder: - std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() ); - break; - case RunTests::InRandomOrder: - { - RandomNumberGenerator rng; - std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); - } - break; - case RunTests::InDeclarationOrder: - // already in declaration order - break; - } - } - std::set m_functions; - std::vector m_functionsInOrder; - std::vector m_nonHiddenFunctions; - size_t m_unnamedCount; - }; - - /////////////////////////////////////////////////////////////////////////// - - class FreeFunctionTestCase : public SharedImpl { - public: - - FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} - - virtual void invoke() const { - m_fun(); - } - - private: - virtual ~FreeFunctionTestCase(); - - TestFunction m_fun; - }; - - inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) { - std::string className = classOrQualifiedMethodName; - if( startsWith( className, "&" ) ) - { - std::size_t lastColons = className.rfind( "::" ); - std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); - if( penultimateColons == std::string::npos ) - penultimateColons = 1; - className = className.substr( penultimateColons, lastColons-penultimateColons ); - } - return className; - } - - /////////////////////////////////////////////////////////////////////////// - - AutoReg::AutoReg( TestFunction function, - SourceLineInfo const& lineInfo, - NameAndDesc const& nameAndDesc ) { - registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo ); - } - - AutoReg::~AutoReg() {} - - void AutoReg::registerTestCase( ITestCase* testCase, - char const* classOrQualifiedMethodName, - NameAndDesc const& nameAndDesc, - SourceLineInfo const& lineInfo ) { - - getMutableRegistryHub().registerTest - ( makeTestCase( testCase, - extractClassName( classOrQualifiedMethodName ), - nameAndDesc.name, - nameAndDesc.description, - lineInfo ) ); - } - -} // end namespace Catch - -// #included from: catch_reporter_registry.hpp -#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED - -#include - -namespace Catch { - - class ReporterRegistry : public IReporterRegistry { - - public: - - virtual ~ReporterRegistry() { - deleteAllValues( m_factories ); - } - - virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const { - FactoryMap::const_iterator it = m_factories.find( name ); - if( it == m_factories.end() ) - return NULL; - return it->second->create( ReporterConfig( config ) ); - } - - void registerReporter( std::string const& name, IReporterFactory* factory ) { - m_factories.insert( std::make_pair( name, factory ) ); - } - - FactoryMap const& getFactories() const { - return m_factories; - } - - private: - FactoryMap m_factories; - }; -} - -// #included from: catch_exception_translator_registry.hpp -#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED - -#ifdef __OBJC__ -#import "Foundation/Foundation.h" -#endif - -namespace Catch { - - class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { - public: - ~ExceptionTranslatorRegistry() { - deleteAll( m_translators ); - } - - virtual void registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( translator ); - } - - virtual std::string translateActiveException() const { - try { -#ifdef __OBJC__ - // In Objective-C try objective-c exceptions first - @try { - throw; - } - @catch (NSException *exception) { - return Catch::toString( [exception description] ); - } -#else - throw; -#endif - } - catch( TestFailureException& ) { - throw; - } - catch( std::exception& ex ) { - return ex.what(); - } - catch( std::string& msg ) { - return msg; - } - catch( const char* msg ) { - return msg; - } - catch(...) { - return tryTranslators( m_translators.begin() ); - } - } - - std::string tryTranslators( std::vector::const_iterator it ) const { - if( it == m_translators.end() ) - return "Unknown exception"; - - try { - return (*it)->translate(); - } - catch(...) { - return tryTranslators( it+1 ); - } - } - - private: - std::vector m_translators; - }; -} - -namespace Catch { - - namespace { - - class RegistryHub : public IRegistryHub, public IMutableRegistryHub { - - RegistryHub( RegistryHub const& ); - void operator=( RegistryHub const& ); - - public: // IRegistryHub - RegistryHub() { - } - virtual IReporterRegistry const& getReporterRegistry() const { - return m_reporterRegistry; - } - virtual ITestCaseRegistry const& getTestCaseRegistry() const { - return m_testCaseRegistry; - } - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() { - return m_exceptionTranslatorRegistry; - } - - public: // IMutableRegistryHub - virtual void registerReporter( std::string const& name, IReporterFactory* factory ) { - m_reporterRegistry.registerReporter( name, factory ); - } - virtual void registerTest( TestCase const& testInfo ) { - m_testCaseRegistry.registerTest( testInfo ); - } - virtual void registerTranslator( const IExceptionTranslator* translator ) { - m_exceptionTranslatorRegistry.registerTranslator( translator ); - } - - private: - TestRegistry m_testCaseRegistry; - ReporterRegistry m_reporterRegistry; - ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; - }; - - // Single, global, instance - inline RegistryHub*& getTheRegistryHub() { - static RegistryHub* theRegistryHub = NULL; - if( !theRegistryHub ) - theRegistryHub = new RegistryHub(); - return theRegistryHub; - } - } - - IRegistryHub& getRegistryHub() { - return *getTheRegistryHub(); - } - IMutableRegistryHub& getMutableRegistryHub() { - return *getTheRegistryHub(); - } - void cleanUp() { - delete getTheRegistryHub(); - getTheRegistryHub() = NULL; - cleanUpContext(); - } - std::string translateActiveException() { - return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); - } - -} // end namespace Catch - -// #included from: catch_notimplemented_exception.hpp -#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED - -#include - -namespace Catch { - - NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo ) - : m_lineInfo( lineInfo ) { - std::ostringstream oss; - oss << lineInfo << ": function "; - oss << "not implemented"; - m_what = oss.str(); - } - - const char* NotImplementedException::what() const CATCH_NOEXCEPT { - return m_what.c_str(); - } - -} // end namespace Catch - -// #included from: catch_context_impl.hpp -#define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED - -// #included from: catch_stream.hpp -#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED - -// #included from: catch_streambuf.h -#define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED - -#include - -namespace Catch { - - class StreamBufBase : public std::streambuf { - public: - virtual ~StreamBufBase() CATCH_NOEXCEPT; - }; -} - -#include -#include -#include - -namespace Catch { - - template - class StreamBufImpl : public StreamBufBase { - char data[bufferSize]; - WriterF m_writer; - - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); - } - - ~StreamBufImpl() CATCH_NOEXCEPT { - sync(); - } - - private: - int overflow( int c ) { - sync(); - - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast( c ) ) ); - else - sputc( static_cast( c ) ); - } - return 0; - } - - int sync() { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - struct OutputDebugWriter { - - void operator()( std::string const&str ) { - writeToDebugConsole( str ); - } - }; - - Stream::Stream() - : streamBuf( NULL ), isOwned( false ) - {} - - Stream::Stream( std::streambuf* _streamBuf, bool _isOwned ) - : streamBuf( _streamBuf ), isOwned( _isOwned ) - {} - - void Stream::release() { - if( isOwned ) { - delete streamBuf; - streamBuf = NULL; - isOwned = false; - } - } - -#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement this functions - std::ostream& cout() { - return std::cout; - } - std::ostream& cerr() { - return std::cerr; - } -#endif -} - -namespace Catch { - - class Context : public IMutableContext { - - Context() : m_config( NULL ), m_runner( NULL ), m_resultCapture( NULL ) {} - Context( Context const& ); - void operator=( Context const& ); - - public: // IContext - virtual IResultCapture* getResultCapture() { - return m_resultCapture; - } - virtual IRunner* getRunner() { - return m_runner; - } - virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) { - return getGeneratorsForCurrentTest() - .getGeneratorInfo( fileInfo, totalSize ) - .getCurrentIndex(); - } - virtual bool advanceGeneratorsForCurrentTest() { - IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); - return generators && generators->moveNext(); - } - - virtual Ptr getConfig() const { - return m_config; - } - - public: // IMutableContext - virtual void setResultCapture( IResultCapture* resultCapture ) { - m_resultCapture = resultCapture; - } - virtual void setRunner( IRunner* runner ) { - m_runner = runner; - } - virtual void setConfig( Ptr const& config ) { - m_config = config; - } - - friend IMutableContext& getCurrentMutableContext(); - - private: - IGeneratorsForTest* findGeneratorsForCurrentTest() { - std::string testName = getResultCapture()->getCurrentTestName(); - - std::map::const_iterator it = - m_generatorsByTestName.find( testName ); - return it != m_generatorsByTestName.end() - ? it->second - : NULL; - } - - IGeneratorsForTest& getGeneratorsForCurrentTest() { - IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); - if( !generators ) { - std::string testName = getResultCapture()->getCurrentTestName(); - generators = createGeneratorsForTest(); - m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); - } - return *generators; - } - - private: - Ptr m_config; - IRunner* m_runner; - IResultCapture* m_resultCapture; - std::map m_generatorsByTestName; - }; - - namespace { - Context* currentContext = NULL; - } - IMutableContext& getCurrentMutableContext() { - if( !currentContext ) - currentContext = new Context(); - return *currentContext; - } - IContext& getCurrentContext() { - return getCurrentMutableContext(); - } - - Stream createStream( std::string const& streamName ) { - if( streamName == "stdout" ) return Stream( Catch::cout().rdbuf(), false ); - if( streamName == "stderr" ) return Stream( Catch::cerr().rdbuf(), false ); - if( streamName == "debug" ) return Stream( new StreamBufImpl, true ); - - throw std::domain_error( "Unknown stream: " + streamName ); - } - - void cleanUpContext() { - delete currentContext; - currentContext = NULL; - } -} - -// #included from: catch_console_colour_impl.hpp -#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED - -namespace Catch { - namespace { - - struct IColourImpl { - virtual ~IColourImpl() {} - virtual void use( Colour::Code _colourCode ) = 0; - }; - - struct NoColourImpl : IColourImpl { - void use( Colour::Code ) {} - - static IColourImpl* instance() { - static NoColourImpl s_instance; - return &s_instance; - } - }; - - } // anon namespace -} // namespace Catch - -#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) -# ifdef CATCH_PLATFORM_WINDOWS -# define CATCH_CONFIG_COLOUR_WINDOWS -# else -# define CATCH_CONFIG_COLOUR_ANSI -# endif -#endif - -#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// - -#ifndef NOMINMAX -#define NOMINMAX -#endif - -#ifdef __AFXDLL -#include -#else -#include -#endif - -namespace Catch { -namespace { - - class Win32ColourImpl : public IColourImpl { - public: - Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) - { - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); - originalAttributes = csbiInfo.wAttributes; - } - - virtual void use( Colour::Code _colourCode ) { - switch( _colourCode ) { - case Colour::None: return setTextAttribute( originalAttributes ); - case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - case Colour::Red: return setTextAttribute( FOREGROUND_RED ); - case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); - case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); - case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); - case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); - case Colour::Grey: return setTextAttribute( 0 ); - - case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); - case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); - case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); - case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - - case Colour::Bright: throw std::logic_error( "not a colour" ); - } - } - - private: - void setTextAttribute( WORD _textAttribute ) { - SetConsoleTextAttribute( stdoutHandle, _textAttribute ); - } - HANDLE stdoutHandle; - WORD originalAttributes; - }; - - IColourImpl* platformColourInstance() { - static Win32ColourImpl s_instance; - return &s_instance; - } - -} // end anon namespace -} // end namespace Catch - -#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// - -#include - -namespace Catch { -namespace { - - // use POSIX/ ANSI console terminal codes - // Thanks to Adam Strzelecki for original contribution - // (http://github.com/nanoant) - // https://github.com/philsquared/Catch/pull/131 - class PosixColourImpl : public IColourImpl { - public: - virtual void use( Colour::Code _colourCode ) { - switch( _colourCode ) { - case Colour::None: - case Colour::White: return setColour( "[0m" ); - case Colour::Red: return setColour( "[0;31m" ); - case Colour::Green: return setColour( "[0;32m" ); - case Colour::Blue: return setColour( "[0:34m" ); - case Colour::Cyan: return setColour( "[0;36m" ); - case Colour::Yellow: return setColour( "[0;33m" ); - case Colour::Grey: return setColour( "[1;30m" ); - - case Colour::LightGrey: return setColour( "[0;37m" ); - case Colour::BrightRed: return setColour( "[1;31m" ); - case Colour::BrightGreen: return setColour( "[1;32m" ); - case Colour::BrightWhite: return setColour( "[1;37m" ); - - case Colour::Bright: throw std::logic_error( "not a colour" ); - } - } - static IColourImpl* instance() { - static PosixColourImpl s_instance; - return &s_instance; - } - - private: - void setColour( const char* _escapeCode ) { - Catch::cout() << '\033' << _escapeCode; - } - }; - - IColourImpl* platformColourInstance() { - Ptr config = getCurrentContext().getConfig(); - return (config && config->forceColour()) || isatty(STDOUT_FILENO) - ? PosixColourImpl::instance() - : NoColourImpl::instance(); - } - -} // end anon namespace -} // end namespace Catch - -#else // not Windows or ANSI /////////////////////////////////////////////// - -namespace Catch { - - static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } - -} // end namespace Catch - -#endif // Windows/ ANSI/ None - -namespace Catch { - - Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); } - Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast( _other ).m_moved = true; } - Colour::~Colour(){ if( !m_moved ) use( None ); } - - void Colour::use( Code _colourCode ) { - static IColourImpl* impl = isDebuggerActive() - ? NoColourImpl::instance() - : platformColourInstance(); - impl->use( _colourCode ); - } - -} // end namespace Catch - -// #included from: catch_generators_impl.hpp -#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED - -#include -#include -#include - -namespace Catch { - - struct GeneratorInfo : IGeneratorInfo { - - GeneratorInfo( std::size_t size ) - : m_size( size ), - m_currentIndex( 0 ) - {} - - bool moveNext() { - if( ++m_currentIndex == m_size ) { - m_currentIndex = 0; - return false; - } - return true; - } - - std::size_t getCurrentIndex() const { - return m_currentIndex; - } - - std::size_t m_size; - std::size_t m_currentIndex; - }; - - /////////////////////////////////////////////////////////////////////////// - - class GeneratorsForTest : public IGeneratorsForTest { - - public: - ~GeneratorsForTest() { - deleteAll( m_generatorsInOrder ); - } - - IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) { - std::map::const_iterator it = m_generatorsByName.find( fileInfo ); - if( it == m_generatorsByName.end() ) { - IGeneratorInfo* info = new GeneratorInfo( size ); - m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); - m_generatorsInOrder.push_back( info ); - return *info; - } - return *it->second; - } - - bool moveNext() { - std::vector::const_iterator it = m_generatorsInOrder.begin(); - std::vector::const_iterator itEnd = m_generatorsInOrder.end(); - for(; it != itEnd; ++it ) { - if( (*it)->moveNext() ) - return true; - } - return false; - } - - private: - std::map m_generatorsByName; - std::vector m_generatorsInOrder; - }; - - IGeneratorsForTest* createGeneratorsForTest() - { - return new GeneratorsForTest(); - } - -} // end namespace Catch - -// #included from: catch_assertionresult.hpp -#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED - -namespace Catch { - - AssertionInfo::AssertionInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - std::string const& _capturedExpression, - ResultDisposition::Flags _resultDisposition ) - : macroName( _macroName ), - lineInfo( _lineInfo ), - capturedExpression( _capturedExpression ), - resultDisposition( _resultDisposition ) - {} - - AssertionResult::AssertionResult() {} - - AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) - : m_info( info ), - m_resultData( data ) - {} - - AssertionResult::~AssertionResult() {} - - // Result was a success - bool AssertionResult::succeeded() const { - return Catch::isOk( m_resultData.resultType ); - } - - // Result was a success, or failure is suppressed - bool AssertionResult::isOk() const { - return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); - } - - ResultWas::OfType AssertionResult::getResultType() const { - return m_resultData.resultType; - } - - bool AssertionResult::hasExpression() const { - return !m_info.capturedExpression.empty(); - } - - bool AssertionResult::hasMessage() const { - return !m_resultData.message.empty(); - } - - std::string AssertionResult::getExpression() const { - if( isFalseTest( m_info.resultDisposition ) ) - return "!" + m_info.capturedExpression; - else - return m_info.capturedExpression; - } - std::string AssertionResult::getExpressionInMacro() const { - if( m_info.macroName.empty() ) - return m_info.capturedExpression; - else - return m_info.macroName + "( " + m_info.capturedExpression + " )"; - } - - bool AssertionResult::hasExpandedExpression() const { - return hasExpression() && getExpandedExpression() != getExpression(); - } - - std::string AssertionResult::getExpandedExpression() const { - return m_resultData.reconstructedExpression; - } - - std::string AssertionResult::getMessage() const { - return m_resultData.message; - } - SourceLineInfo AssertionResult::getSourceInfo() const { - return m_info.lineInfo; - } - - std::string AssertionResult::getTestMacroName() const { - return m_info.macroName; - } - -} // end namespace Catch - -// #included from: catch_test_case_info.hpp -#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED - -namespace Catch { - - inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { - if( startsWith( tag, "." ) || - tag == "hide" || - tag == "!hide" ) - return TestCaseInfo::IsHidden; - else if( tag == "!throws" ) - return TestCaseInfo::Throws; - else if( tag == "!shouldfail" ) - return TestCaseInfo::ShouldFail; - else if( tag == "!mayfail" ) - return TestCaseInfo::MayFail; - else - return TestCaseInfo::None; - } - inline bool isReservedTag( std::string const& tag ) { - return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !isalnum( tag[0] ); - } - inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { - if( isReservedTag( tag ) ) { - { - Colour colourGuard( Colour::Red ); - Catch::cerr() - << "Tag name [" << tag << "] not allowed.\n" - << "Tag names starting with non alpha-numeric characters are reserved\n"; - } - { - Colour colourGuard( Colour::FileName ); - Catch::cerr() << _lineInfo << std::endl; - } - exit(1); - } - } - - TestCase makeTestCase( ITestCase* _testCase, - std::string const& _className, - std::string const& _name, - std::string const& _descOrTags, - SourceLineInfo const& _lineInfo ) - { - bool isHidden( startsWith( _name, "./" ) ); // Legacy support - - // Parse out tags - std::set tags; - std::string desc, tag; - bool inTag = false; - for( std::size_t i = 0; i < _descOrTags.size(); ++i ) { - char c = _descOrTags[i]; - if( !inTag ) { - if( c == '[' ) - inTag = true; - else - desc += c; - } - else { - if( c == ']' ) { - TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); - if( prop == TestCaseInfo::IsHidden ) - isHidden = true; - else if( prop == TestCaseInfo::None ) - enforceNotReservedTag( tag, _lineInfo ); - - tags.insert( tag ); - tag.clear(); - inTag = false; - } - else - tag += c; - } - } - if( isHidden ) { - tags.insert( "hide" ); - tags.insert( "." ); - } - - TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); - return TestCase( _testCase, info ); - } - - TestCaseInfo::TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::set const& _tags, - SourceLineInfo const& _lineInfo ) - : name( _name ), - className( _className ), - description( _description ), - tags( _tags ), - lineInfo( _lineInfo ), - properties( None ) - { - std::ostringstream oss; - for( std::set::const_iterator it = _tags.begin(), itEnd = _tags.end(); it != itEnd; ++it ) { - oss << "[" << *it << "]"; - std::string lcaseTag = toLower( *it ); - properties = static_cast( properties | parseSpecialTag( lcaseTag ) ); - lcaseTags.insert( lcaseTag ); - } - tagsAsString = oss.str(); - } - - TestCaseInfo::TestCaseInfo( TestCaseInfo const& other ) - : name( other.name ), - className( other.className ), - description( other.description ), - tags( other.tags ), - lcaseTags( other.lcaseTags ), - tagsAsString( other.tagsAsString ), - lineInfo( other.lineInfo ), - properties( other.properties ) - {} - - bool TestCaseInfo::isHidden() const { - return ( properties & IsHidden ) != 0; - } - bool TestCaseInfo::throws() const { - return ( properties & Throws ) != 0; - } - bool TestCaseInfo::okToFail() const { - return ( properties & (ShouldFail | MayFail ) ) != 0; - } - bool TestCaseInfo::expectedToFail() const { - return ( properties & (ShouldFail ) ) != 0; - } - - TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} - - TestCase::TestCase( TestCase const& other ) - : TestCaseInfo( other ), - test( other.test ) - {} - - TestCase TestCase::withName( std::string const& _newName ) const { - TestCase other( *this ); - other.name = _newName; - return other; - } - - void TestCase::swap( TestCase& other ) { - test.swap( other.test ); - name.swap( other.name ); - className.swap( other.className ); - description.swap( other.description ); - tags.swap( other.tags ); - lcaseTags.swap( other.lcaseTags ); - tagsAsString.swap( other.tagsAsString ); - std::swap( TestCaseInfo::properties, static_cast( other ).properties ); - std::swap( lineInfo, other.lineInfo ); - } - - void TestCase::invoke() const { - test->invoke(); - } - - bool TestCase::operator == ( TestCase const& other ) const { - return test.get() == other.test.get() && - name == other.name && - className == other.className; - } - - bool TestCase::operator < ( TestCase const& other ) const { - return name < other.name; - } - TestCase& TestCase::operator = ( TestCase const& other ) { - TestCase temp( other ); - swap( temp ); - return *this; - } - - TestCaseInfo const& TestCase::getTestCaseInfo() const - { - return *this; - } - -} // end namespace Catch - -// #included from: catch_version.hpp -#define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED - -namespace Catch { - - Version::Version - ( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - std::string const& _branchName, - unsigned int _buildNumber ) - : majorVersion( _majorVersion ), - minorVersion( _minorVersion ), - patchNumber( _patchNumber ), - branchName( _branchName ), - buildNumber( _buildNumber ) - {} - - std::ostream& operator << ( std::ostream& os, Version const& version ) { - os << version.majorVersion << "." - << version.minorVersion << "." - << version.patchNumber; - - if( !version.branchName.empty() ) { - os << "-" << version.branchName - << "." << version.buildNumber; - } - return os; - } - - Version libraryVersion( 1, 2, 1, "", 0 ); - -} - -// #included from: catch_message.hpp -#define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED - -namespace Catch { - - MessageInfo::MessageInfo( std::string const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ) - : macroName( _macroName ), - lineInfo( _lineInfo ), - type( _type ), - sequence( ++globalCount ) - {} - - // This may need protecting if threading support is added - unsigned int MessageInfo::globalCount = 0; - - //////////////////////////////////////////////////////////////////////////// - - ScopedMessage::ScopedMessage( MessageBuilder const& builder ) - : m_info( builder.m_info ) - { - m_info.message = builder.m_stream.str(); - getResultCapture().pushScopedMessage( m_info ); - } - ScopedMessage::ScopedMessage( ScopedMessage const& other ) - : m_info( other.m_info ) - {} - - ScopedMessage::~ScopedMessage() { - getResultCapture().popScopedMessage( m_info ); - } - -} // end namespace Catch - -// #included from: catch_legacy_reporter_adapter.hpp -#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED - -// #included from: catch_legacy_reporter_adapter.h -#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED - -namespace Catch -{ - // Deprecated - struct IReporter : IShared { - virtual ~IReporter(); - - virtual bool shouldRedirectStdout() const = 0; - - virtual void StartTesting() = 0; - virtual void EndTesting( Totals const& totals ) = 0; - virtual void StartGroup( std::string const& groupName ) = 0; - virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0; - virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0; - virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0; - virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0; - virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0; - virtual void NoAssertionsInSection( std::string const& sectionName ) = 0; - virtual void NoAssertionsInTestCase( std::string const& testName ) = 0; - virtual void Aborted() = 0; - virtual void Result( AssertionResult const& result ) = 0; - }; - - class LegacyReporterAdapter : public SharedImpl - { - public: - LegacyReporterAdapter( Ptr const& legacyReporter ); - virtual ~LegacyReporterAdapter(); - - virtual ReporterPreferences getPreferences() const; - virtual void noMatchingTestCases( std::string const& ); - virtual void testRunStarting( TestRunInfo const& ); - virtual void testGroupStarting( GroupInfo const& groupInfo ); - virtual void testCaseStarting( TestCaseInfo const& testInfo ); - virtual void sectionStarting( SectionInfo const& sectionInfo ); - virtual void assertionStarting( AssertionInfo const& ); - virtual bool assertionEnded( AssertionStats const& assertionStats ); - virtual void sectionEnded( SectionStats const& sectionStats ); - virtual void testCaseEnded( TestCaseStats const& testCaseStats ); - virtual void testGroupEnded( TestGroupStats const& testGroupStats ); - virtual void testRunEnded( TestRunStats const& testRunStats ); - virtual void skipTest( TestCaseInfo const& ); - - private: - Ptr m_legacyReporter; - }; -} - -namespace Catch -{ - LegacyReporterAdapter::LegacyReporterAdapter( Ptr const& legacyReporter ) - : m_legacyReporter( legacyReporter ) - {} - LegacyReporterAdapter::~LegacyReporterAdapter() {} - - ReporterPreferences LegacyReporterAdapter::getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout(); - return prefs; - } - - void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {} - void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) { - m_legacyReporter->StartTesting(); - } - void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) { - m_legacyReporter->StartGroup( groupInfo.name ); - } - void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) { - m_legacyReporter->StartTestCase( testInfo ); - } - void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) { - m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); - } - void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) { - // Not on legacy interface - } - - bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { - if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { - for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); - it != itEnd; - ++it ) { - if( it->type == ResultWas::Info ) { - ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal ); - rb << it->message; - rb.setResultType( ResultWas::Info ); - AssertionResult result = rb.build(); - m_legacyReporter->Result( result ); - } - } - } - m_legacyReporter->Result( assertionStats.assertionResult ); - return true; - } - void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) { - if( sectionStats.missingAssertions ) - m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); - m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); - } - void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) { - m_legacyReporter->EndTestCase - ( testCaseStats.testInfo, - testCaseStats.totals, - testCaseStats.stdOut, - testCaseStats.stdErr ); - } - void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) { - if( testGroupStats.aborting ) - m_legacyReporter->Aborted(); - m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals ); - } - void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) { - m_legacyReporter->EndTesting( testRunStats.totals ); - } - void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) { - } -} - -// #included from: catch_timer.hpp - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wc++11-long-long" -#endif - -#ifdef CATCH_PLATFORM_WINDOWS -#include -#else -#include -#endif - -namespace Catch { - - namespace { -#ifdef CATCH_PLATFORM_WINDOWS - uint64_t getCurrentTicks() { - static uint64_t hz=0, hzo=0; - if (!hz) { - QueryPerformanceFrequency( reinterpret_cast( &hz ) ); - QueryPerformanceCounter( reinterpret_cast( &hzo ) ); - } - uint64_t t; - QueryPerformanceCounter( reinterpret_cast( &t ) ); - return ((t-hzo)*1000000)/hz; - } -#else - uint64_t getCurrentTicks() { - timeval t; - gettimeofday(&t,NULL); - return static_cast( t.tv_sec ) * 1000000ull + static_cast( t.tv_usec ); - } -#endif - } - - void Timer::start() { - m_ticks = getCurrentTicks(); - } - unsigned int Timer::getElapsedMicroseconds() const { - return static_cast(getCurrentTicks() - m_ticks); - } - unsigned int Timer::getElapsedMilliseconds() const { - return static_cast(getElapsedMicroseconds()/1000); - } - double Timer::getElapsedSeconds() const { - return getElapsedMicroseconds()/1000000.0; - } - -} // namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -// #included from: catch_common.hpp -#define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED - -namespace Catch { - - bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix; - } - bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix; - } - bool contains( std::string const& s, std::string const& infix ) { - return s.find( infix ) != std::string::npos; - } - void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), ::tolower ); - } - std::string toLower( std::string const& s ) { - std::string lc = s; - toLowerInPlace( lc ); - return lc; - } - std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; - std::string::size_type start = str.find_first_not_of( whitespaceChars ); - std::string::size_type end = str.find_last_not_of( whitespaceChars ); - - return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; - } - - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { - bool replaced = false; - std::size_t i = str.find( replaceThis ); - while( i != std::string::npos ) { - replaced = true; - str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); - if( i < str.size()-withThis.size() ) - i = str.find( replaceThis, i+withThis.size() ); - else - i = std::string::npos; - } - return replaced; - } - - pluralise::pluralise( std::size_t count, std::string const& label ) - : m_count( count ), - m_label( label ) - {} - - std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << " " << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << "s"; - return os; - } - - SourceLineInfo::SourceLineInfo() : line( 0 ){} - SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) - : file( _file ), - line( _line ) - {} - SourceLineInfo::SourceLineInfo( SourceLineInfo const& other ) - : file( other.file ), - line( other.line ) - {} - bool SourceLineInfo::empty() const { - return file.empty(); - } - bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const { - return line == other.line && file == other.file; - } - bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const { - return line < other.line || ( line == other.line && file < other.file ); - } - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { -#ifndef __GNUG__ - os << info.file << "(" << info.line << ")"; -#else - os << info.file << ":" << info.line; -#endif - return os; - } - - void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) { - std::ostringstream oss; - oss << locationInfo << ": Internal Catch error: '" << message << "'"; - if( alwaysTrue() ) - throw std::logic_error( oss.str() ); - } -} - -// #included from: catch_section.hpp -#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED - -namespace Catch { - - SectionInfo::SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description ) - : name( _name ), - description( _description ), - lineInfo( _lineInfo ) - {} - - Section::Section( SectionInfo const& info ) - : m_info( info ), - m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) - { - m_timer.start(); - } - - Section::~Section() { - if( m_sectionIncluded ) - getResultCapture().sectionEnded( m_info, m_assertions, m_timer.getElapsedSeconds() ); - } - - // This indicates whether the section should be executed or not - Section::operator bool() const { - return m_sectionIncluded; - } - -} // end namespace Catch - -// #included from: catch_debugger.hpp -#define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED - -#include - -#ifdef CATCH_PLATFORM_MAC - - #include - #include - #include - #include - #include - - namespace Catch{ - - // The following function is taken directly from the following technical note: - // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html - - // Returns true if the current process is being debugged (either - // running under the debugger or has a debugger attached post facto). - bool isDebuggerActive(){ - - int mib[4]; - struct kinfo_proc info; - size_t size; - - // Initialize the flags so that, if sysctl fails for some bizarre - // reason, we get a predictable result. - - info.kp_proc.p_flag = 0; - - // Initialize mib, which tells sysctl the info we want, in this case - // we're looking for information about a specific process ID. - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = getpid(); - - // Call sysctl. - - size = sizeof(info); - if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) != 0 ) { - Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; - return false; - } - - // We're being debugged if the P_TRACED flag is set. - - return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); - } - } // namespace Catch - -#elif defined(_MSC_VER) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#else - namespace Catch { - inline bool isDebuggerActive() { return false; } - } -#endif // Platform - -#ifdef CATCH_PLATFORM_WINDOWS - extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* ); - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - ::OutputDebugStringA( text.c_str() ); - } - } -#else - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - // !TBD: Need a version for Mac/ XCode and other IDEs - Catch::cout() << text; - } - } -#endif // Platform - -// #included from: catch_tostring.hpp -#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED - -namespace Catch { - -namespace Detail { - - std::string unprintableString = "{?}"; - - namespace { - struct Endianness { - enum Arch { Big, Little }; - - static Arch which() { - union _{ - int asInt; - char asChar[sizeof (int)]; - } u; - - u.asInt = 1; - return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; - } - }; - } - - std::string rawMemoryToString( const void *object, std::size_t size ) - { - // Reverse order for little endian architectures - int i = 0, end = static_cast( size ), inc = 1; - if( Endianness::which() == Endianness::Little ) { - i = end-1; - end = inc = -1; - } - - unsigned char const *bytes = static_cast(object); - std::ostringstream os; - os << "0x" << std::setfill('0') << std::hex; - for( ; i != end; i += inc ) - os << std::setw(2) << static_cast(bytes[i]); - return os.str(); - } -} - -std::string toString( std::string const& value ) { - std::string s = value; - if( getCurrentContext().getConfig()->showInvisibles() ) { - for(size_t i = 0; i < s.size(); ++i ) { - std::string subs; - switch( s[i] ) { - case '\n': subs = "\\n"; break; - case '\t': subs = "\\t"; break; - default: break; - } - if( !subs.empty() ) { - s = s.substr( 0, i ) + subs + s.substr( i+1 ); - ++i; - } - } - } - return "\"" + s + "\""; -} -std::string toString( std::wstring const& value ) { - - std::string s; - s.reserve( value.size() ); - for(size_t i = 0; i < value.size(); ++i ) - s += value[i] <= 0xff ? static_cast( value[i] ) : '?'; - return Catch::toString( s ); -} - -std::string toString( const char* const value ) { - return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" ); -} - -std::string toString( char* const value ) { - return Catch::toString( static_cast( value ) ); -} - -std::string toString( const wchar_t* const value ) -{ - return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); -} - -std::string toString( wchar_t* const value ) -{ - return Catch::toString( static_cast( value ) ); -} - -std::string toString( int value ) { - std::ostringstream oss; - oss << value; - if( value >= 255 ) - oss << " (0x" << std::hex << value << ")"; - return oss.str(); -} - -std::string toString( unsigned long value ) { - std::ostringstream oss; - oss << value; - if( value >= 255 ) - oss << " (0x" << std::hex << value << ")"; - return oss.str(); -} - -std::string toString( unsigned int value ) { - return Catch::toString( static_cast( value ) ); -} - -template -std::string fpToString( T value, int precision ) { - std::ostringstream oss; - oss << std::setprecision( precision ) - << std::fixed - << value; - std::string d = oss.str(); - std::size_t i = d.find_last_not_of( '0' ); - if( i != std::string::npos && i != d.size()-1 ) { - if( d[i] == '.' ) - i++; - d = d.substr( 0, i+1 ); - } - return d; -} - -std::string toString( const double value ) { - return fpToString( value, 10 ); -} -std::string toString( const float value ) { - return fpToString( value, 5 ) + "f"; -} - -std::string toString( bool value ) { - return value ? "true" : "false"; -} - -std::string toString( char value ) { - return value < ' ' - ? toString( static_cast( value ) ) - : Detail::makeString( value ); -} - -std::string toString( signed char value ) { - return toString( static_cast( value ) ); -} - -std::string toString( unsigned char value ) { - return toString( static_cast( value ) ); -} - -#ifdef CATCH_CONFIG_CPP11_NULLPTR -std::string toString( std::nullptr_t ) { - return "nullptr"; -} -#endif - -#ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ) { - if( !nsstring ) - return "nil"; - return "@" + toString([nsstring UTF8String]); - } - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) { - if( !nsstring ) - return "nil"; - return "@" + toString([nsstring UTF8String]); - } - std::string toString( NSObject* const& nsObject ) { - return toString( [nsObject description] ); - } -#endif - -} // end namespace Catch - -// #included from: catch_result_builder.hpp -#define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED - -namespace Catch { - - ResultBuilder::ResultBuilder( char const* macroName, - SourceLineInfo const& lineInfo, - char const* capturedExpression, - ResultDisposition::Flags resultDisposition ) - : m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition ), - m_shouldDebugBreak( false ), - m_shouldThrow( false ) - {} - - ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) { - m_data.resultType = result; - return *this; - } - ResultBuilder& ResultBuilder::setResultType( bool result ) { - m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; - return *this; - } - ResultBuilder& ResultBuilder::setLhs( std::string const& lhs ) { - m_exprComponents.lhs = lhs; - return *this; - } - ResultBuilder& ResultBuilder::setRhs( std::string const& rhs ) { - m_exprComponents.rhs = rhs; - return *this; - } - ResultBuilder& ResultBuilder::setOp( std::string const& op ) { - m_exprComponents.op = op; - return *this; - } - - void ResultBuilder::endExpression() { - m_exprComponents.testFalse = isFalseTest( m_assertionInfo.resultDisposition ); - captureExpression(); - } - - void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) { - m_assertionInfo.resultDisposition = resultDisposition; - m_stream.oss << Catch::translateActiveException(); - captureResult( ResultWas::ThrewException ); - } - - void ResultBuilder::captureResult( ResultWas::OfType resultType ) { - setResultType( resultType ); - captureExpression(); - } - - void ResultBuilder::captureExpression() { - AssertionResult result = build(); - getResultCapture().assertionEnded( result ); - - if( !result.isOk() ) { - if( getCurrentContext().getConfig()->shouldDebugBreak() ) - m_shouldDebugBreak = true; - if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) ) - m_shouldThrow = true; - } - } - void ResultBuilder::react() { - if( m_shouldThrow ) - throw Catch::TestFailureException(); - } - - bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; } - bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); } - - AssertionResult ResultBuilder::build() const - { - assert( m_data.resultType != ResultWas::Unknown ); - - AssertionResultData data = m_data; - - // Flip bool results if testFalse is set - if( m_exprComponents.testFalse ) { - if( data.resultType == ResultWas::Ok ) - data.resultType = ResultWas::ExpressionFailed; - else if( data.resultType == ResultWas::ExpressionFailed ) - data.resultType = ResultWas::Ok; - } - - data.message = m_stream.oss.str(); - data.reconstructedExpression = reconstructExpression(); - if( m_exprComponents.testFalse ) { - if( m_exprComponents.op == "" ) - data.reconstructedExpression = "!" + data.reconstructedExpression; - else - data.reconstructedExpression = "!(" + data.reconstructedExpression + ")"; - } - return AssertionResult( m_assertionInfo, data ); - } - std::string ResultBuilder::reconstructExpression() const { - if( m_exprComponents.op == "" ) - return m_exprComponents.lhs.empty() ? m_assertionInfo.capturedExpression : m_exprComponents.op + m_exprComponents.lhs; - else if( m_exprComponents.op == "matches" ) - return m_exprComponents.lhs + " " + m_exprComponents.rhs; - else if( m_exprComponents.op != "!" ) { - if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 40 && - m_exprComponents.lhs.find("\n") == std::string::npos && - m_exprComponents.rhs.find("\n") == std::string::npos ) - return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs; - else - return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs; - } - else - return "{can't expand - use " + m_assertionInfo.macroName + "_FALSE( " + m_assertionInfo.capturedExpression.substr(1) + " ) instead of " + m_assertionInfo.macroName + "( " + m_assertionInfo.capturedExpression + " ) for better diagnostics}"; - } - -} // end namespace Catch - -// #included from: catch_tag_alias_registry.hpp -#define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED - -// #included from: catch_tag_alias_registry.h -#define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED - -#include - -namespace Catch { - - class TagAliasRegistry : public ITagAliasRegistry { - public: - virtual ~TagAliasRegistry(); - virtual Option find( std::string const& alias ) const; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const; - void add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - static TagAliasRegistry& get(); - - private: - std::map m_registry; - }; - -} // end namespace Catch - -#include -#include - -namespace Catch { - - TagAliasRegistry::~TagAliasRegistry() {} - - Option TagAliasRegistry::find( std::string const& alias ) const { - std::map::const_iterator it = m_registry.find( alias ); - if( it != m_registry.end() ) - return it->second; - else - return Option(); - } - - std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { - std::string expandedTestSpec = unexpandedTestSpec; - for( std::map::const_iterator it = m_registry.begin(), itEnd = m_registry.end(); - it != itEnd; - ++it ) { - std::size_t pos = expandedTestSpec.find( it->first ); - if( pos != std::string::npos ) { - expandedTestSpec = expandedTestSpec.substr( 0, pos ) + - it->second.tag + - expandedTestSpec.substr( pos + it->first.size() ); - } - } - return expandedTestSpec; - } - - void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { - - if( !startsWith( alias, "[@" ) || !endsWith( alias, "]" ) ) { - std::ostringstream oss; - oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo; - throw std::domain_error( oss.str().c_str() ); - } - if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) { - std::ostringstream oss; - oss << "error: tag alias, \"" << alias << "\" already registered.\n" - << "\tFirst seen at " << find(alias)->lineInfo << "\n" - << "\tRedefined at " << lineInfo; - throw std::domain_error( oss.str().c_str() ); - } - } - - TagAliasRegistry& TagAliasRegistry::get() { - static TagAliasRegistry instance; - return instance; - - } - - ITagAliasRegistry::~ITagAliasRegistry() {} - ITagAliasRegistry const& ITagAliasRegistry::get() { return TagAliasRegistry::get(); } - - RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { - try { - TagAliasRegistry::get().add( alias, tag, lineInfo ); - } - catch( std::exception& ex ) { - Colour colourGuard( Colour::Red ); - Catch::cerr() << ex.what() << std::endl; - exit(1); - } - } - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_xml.hpp -#define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED - -// #included from: catch_reporter_bases.hpp -#define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED - -#include - -namespace Catch { - - struct StreamingReporterBase : SharedImpl { - - StreamingReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - {} - - virtual ~StreamingReporterBase(); - - virtual void noMatchingTestCases( std::string const& ) {} - - virtual void testRunStarting( TestRunInfo const& _testRunInfo ) { - currentTestRunInfo = _testRunInfo; - } - virtual void testGroupStarting( GroupInfo const& _groupInfo ) { - currentGroupInfo = _groupInfo; - } - - virtual void testCaseStarting( TestCaseInfo const& _testInfo ) { - currentTestCaseInfo = _testInfo; - } - virtual void sectionStarting( SectionInfo const& _sectionInfo ) { - m_sectionStack.push_back( _sectionInfo ); - } - - virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) { - m_sectionStack.pop_back(); - } - virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) { - currentTestCaseInfo.reset(); - } - virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) { - currentGroupInfo.reset(); - } - virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) { - currentTestCaseInfo.reset(); - currentGroupInfo.reset(); - currentTestRunInfo.reset(); - } - - virtual void skipTest( TestCaseInfo const& ) { - // Don't do anything with this by default. - // It can optionally be overridden in the derived class. - } - - Ptr m_config; - std::ostream& stream; - - LazyStat currentTestRunInfo; - LazyStat currentGroupInfo; - LazyStat currentTestCaseInfo; - - std::vector m_sectionStack; - }; - - struct CumulativeReporterBase : SharedImpl { - template - struct Node : SharedImpl<> { - explicit Node( T const& _value ) : value( _value ) {} - virtual ~Node() {} - - typedef std::vector > ChildNodes; - T value; - ChildNodes children; - }; - struct SectionNode : SharedImpl<> { - explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {} - virtual ~SectionNode(); - - bool operator == ( SectionNode const& other ) const { - return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; - } - bool operator == ( Ptr const& other ) const { - return operator==( *other ); - } - - SectionStats stats; - typedef std::vector > ChildSections; - typedef std::vector Assertions; - ChildSections childSections; - Assertions assertions; - std::string stdOut; - std::string stdErr; - }; - - struct BySectionInfo { - BySectionInfo( SectionInfo const& other ) : m_other( other ) {} - BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} - bool operator() ( Ptr const& node ) const { - return node->stats.sectionInfo.lineInfo == m_other.lineInfo; - } - private: - void operator=( BySectionInfo const& ); - SectionInfo const& m_other; - }; - - typedef Node TestCaseNode; - typedef Node TestGroupNode; - typedef Node TestRunNode; - - CumulativeReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - {} - ~CumulativeReporterBase(); - - virtual void testRunStarting( TestRunInfo const& ) {} - virtual void testGroupStarting( GroupInfo const& ) {} - - virtual void testCaseStarting( TestCaseInfo const& ) {} - - virtual void sectionStarting( SectionInfo const& sectionInfo ) { - SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); - Ptr node; - if( m_sectionStack.empty() ) { - if( !m_rootSection ) - m_rootSection = new SectionNode( incompleteStats ); - node = m_rootSection; - } - else { - SectionNode& parentNode = *m_sectionStack.back(); - SectionNode::ChildSections::const_iterator it = - std::find_if( parentNode.childSections.begin(), - parentNode.childSections.end(), - BySectionInfo( sectionInfo ) ); - if( it == parentNode.childSections.end() ) { - node = new SectionNode( incompleteStats ); - parentNode.childSections.push_back( node ); - } - else - node = *it; - } - m_sectionStack.push_back( node ); - m_deepestSection = node; - } - - virtual void assertionStarting( AssertionInfo const& ) {} - - virtual bool assertionEnded( AssertionStats const& assertionStats ) { - assert( !m_sectionStack.empty() ); - SectionNode& sectionNode = *m_sectionStack.back(); - sectionNode.assertions.push_back( assertionStats ); - return true; - } - virtual void sectionEnded( SectionStats const& sectionStats ) { - assert( !m_sectionStack.empty() ); - SectionNode& node = *m_sectionStack.back(); - node.stats = sectionStats; - m_sectionStack.pop_back(); - } - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { - Ptr node = new TestCaseNode( testCaseStats ); - assert( m_sectionStack.size() == 0 ); - node->children.push_back( m_rootSection ); - m_testCases.push_back( node ); - m_rootSection.reset(); - - assert( m_deepestSection ); - m_deepestSection->stdOut = testCaseStats.stdOut; - m_deepestSection->stdErr = testCaseStats.stdErr; - } - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { - Ptr node = new TestGroupNode( testGroupStats ); - node->children.swap( m_testCases ); - m_testGroups.push_back( node ); - } - virtual void testRunEnded( TestRunStats const& testRunStats ) { - Ptr node = new TestRunNode( testRunStats ); - node->children.swap( m_testGroups ); - m_testRuns.push_back( node ); - testRunEndedCumulative(); - } - virtual void testRunEndedCumulative() = 0; - - virtual void skipTest( TestCaseInfo const& ) {} - - Ptr m_config; - std::ostream& stream; - std::vector m_assertions; - std::vector > > m_sections; - std::vector > m_testCases; - std::vector > m_testGroups; - - std::vector > m_testRuns; - - Ptr m_rootSection; - Ptr m_deepestSection; - std::vector > m_sectionStack; - - }; - - template - char const* getLineOfChars() { - static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; - if( !*line ) { - memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); - line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; - } - return line; - } - -} // end namespace Catch - -// #included from: ../internal/catch_reporter_registrars.hpp -#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED - -namespace Catch { - - template - class LegacyReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - virtual IStreamingReporter* create( ReporterConfig const& config ) const { - return new LegacyReporterAdapter( new T( config ) ); - } - - virtual std::string getDescription() const { - return T::getDescription(); - } - }; - - public: - - LegacyReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); - } - }; - - template - class ReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - - // *** Please Note ***: - // - If you end up here looking at a compiler error because it's trying to register - // your custom reporter class be aware that the native reporter interface has changed - // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via - // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter. - // However please consider updating to the new interface as the old one is now - // deprecated and will probably be removed quite soon! - // Please contact me via github if you have any questions at all about this. - // In fact, ideally, please contact me anyway to let me know you've hit this - as I have - // no idea who is actually using custom reporters at all (possibly no-one!). - // The new interface is designed to minimise exposure to interface changes in the future. - virtual IStreamingReporter* create( ReporterConfig const& config ) const { - return new T( config ); - } - - virtual std::string getDescription() const { - return T::getDescription(); - } - }; - - public: - - ReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); - } - }; -} - -#define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \ - namespace{ Catch::LegacyReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } -#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ - namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } - -// #included from: ../internal/catch_xmlwriter.hpp -#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED - -#include -#include -#include - -namespace Catch { - - class XmlWriter { - public: - - class ScopedElement { - public: - ScopedElement( XmlWriter* writer ) - : m_writer( writer ) - {} - - ScopedElement( ScopedElement const& other ) - : m_writer( other.m_writer ){ - other.m_writer = NULL; - } - - ~ScopedElement() { - if( m_writer ) - m_writer->endElement(); - } - - ScopedElement& writeText( std::string const& text, bool indent = true ) { - m_writer->writeText( text, indent ); - return *this; - } - - template - ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { - m_writer->writeAttribute( name, attribute ); - return *this; - } - - private: - mutable XmlWriter* m_writer; - }; - - XmlWriter() - : m_tagIsOpen( false ), - m_needsNewline( false ), - m_os( &Catch::cout() ) - {} - - XmlWriter( std::ostream& os ) - : m_tagIsOpen( false ), - m_needsNewline( false ), - m_os( &os ) - {} - - ~XmlWriter() { - while( !m_tags.empty() ) - endElement(); - } - - XmlWriter& startElement( std::string const& name ) { - ensureTagClosed(); - newlineIfNecessary(); - stream() << m_indent << "<" << name; - m_tags.push_back( name ); - m_indent += " "; - m_tagIsOpen = true; - return *this; - } - - ScopedElement scopedElement( std::string const& name ) { - ScopedElement scoped( this ); - startElement( name ); - return scoped; - } - - XmlWriter& endElement() { - newlineIfNecessary(); - m_indent = m_indent.substr( 0, m_indent.size()-2 ); - if( m_tagIsOpen ) { - stream() << "/>\n"; - m_tagIsOpen = false; - } - else { - stream() << m_indent << "\n"; - } - m_tags.pop_back(); - return *this; - } - - XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) { - if( !name.empty() && !attribute.empty() ) { - stream() << " " << name << "=\""; - writeEncodedText( attribute ); - stream() << "\""; - } - return *this; - } - - XmlWriter& writeAttribute( std::string const& name, bool attribute ) { - stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\""; - return *this; - } - - template - XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { - if( !name.empty() ) - stream() << " " << name << "=\"" << attribute << "\""; - return *this; - } - - XmlWriter& writeText( std::string const& text, bool indent = true ) { - if( !text.empty() ){ - bool tagWasOpen = m_tagIsOpen; - ensureTagClosed(); - if( tagWasOpen && indent ) - stream() << m_indent; - writeEncodedText( text ); - m_needsNewline = true; - } - return *this; - } - - XmlWriter& writeComment( std::string const& text ) { - ensureTagClosed(); - stream() << m_indent << ""; - m_needsNewline = true; - return *this; - } - - XmlWriter& writeBlankLine() { - ensureTagClosed(); - stream() << "\n"; - return *this; - } - - void setStream( std::ostream& os ) { - m_os = &os; - } - - private: - XmlWriter( XmlWriter const& ); - void operator=( XmlWriter const& ); - - std::ostream& stream() { - return *m_os; - } - - void ensureTagClosed() { - if( m_tagIsOpen ) { - stream() << ">\n"; - m_tagIsOpen = false; - } - } - - void newlineIfNecessary() { - if( m_needsNewline ) { - stream() << "\n"; - m_needsNewline = false; - } - } - - void writeEncodedText( std::string const& text ) { - static const char* charsToEncode = "<&\""; - std::string mtext = text; - std::string::size_type pos = mtext.find_first_of( charsToEncode ); - while( pos != std::string::npos ) { - stream() << mtext.substr( 0, pos ); - - switch( mtext[pos] ) { - case '<': - stream() << "<"; - break; - case '&': - stream() << "&"; - break; - case '\"': - stream() << """; - break; - } - mtext = mtext.substr( pos+1 ); - pos = mtext.find_first_of( charsToEncode ); - } - stream() << mtext; - } - - bool m_tagIsOpen; - bool m_needsNewline; - std::vector m_tags; - std::string m_indent; - std::ostream* m_os; - }; - -} -namespace Catch { - class XmlReporter : public StreamingReporterBase { - public: - XmlReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ), - m_sectionDepth( 0 ) - {} - - virtual ~XmlReporter(); - - static std::string getDescription() { - return "Reports test results as an XML document"; - } - - public: // StreamingReporterBase - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = true; - return prefs; - } - - virtual void noMatchingTestCases( std::string const& s ) { - StreamingReporterBase::noMatchingTestCases( s ); - } - - virtual void testRunStarting( TestRunInfo const& testInfo ) { - StreamingReporterBase::testRunStarting( testInfo ); - m_xml.setStream( stream ); - m_xml.startElement( "Catch" ); - if( !m_config->name().empty() ) - m_xml.writeAttribute( "name", m_config->name() ); - } - - virtual void testGroupStarting( GroupInfo const& groupInfo ) { - StreamingReporterBase::testGroupStarting( groupInfo ); - m_xml.startElement( "Group" ) - .writeAttribute( "name", groupInfo.name ); - } - - virtual void testCaseStarting( TestCaseInfo const& testInfo ) { - StreamingReporterBase::testCaseStarting(testInfo); - m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); - - if ( m_config->showDurations() == ShowDurations::Always ) - m_testCaseTimer.start(); - } - - virtual void sectionStarting( SectionInfo const& sectionInfo ) { - StreamingReporterBase::sectionStarting( sectionInfo ); - if( m_sectionDepth++ > 0 ) { - m_xml.startElement( "Section" ) - .writeAttribute( "name", trim( sectionInfo.name ) ) - .writeAttribute( "description", sectionInfo.description ); - } - } - - virtual void assertionStarting( AssertionInfo const& ) { } - - virtual bool assertionEnded( AssertionStats const& assertionStats ) { - const AssertionResult& assertionResult = assertionStats.assertionResult; - - // Print any info messages in tags. - if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { - for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); - it != itEnd; - ++it ) { - if( it->type == ResultWas::Info ) { - m_xml.scopedElement( "Info" ) - .writeText( it->message ); - } else if ( it->type == ResultWas::Warning ) { - m_xml.scopedElement( "Warning" ) - .writeText( it->message ); - } - } - } - - // Drop out if result was successful but we're not printing them. - if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) ) - return true; - - // Print the expression if there is one. - if( assertionResult.hasExpression() ) { - m_xml.startElement( "Expression" ) - .writeAttribute( "success", assertionResult.succeeded() ) - .writeAttribute( "type", assertionResult.getTestMacroName() ) - .writeAttribute( "filename", assertionResult.getSourceInfo().file ) - .writeAttribute( "line", assertionResult.getSourceInfo().line ); - - m_xml.scopedElement( "Original" ) - .writeText( assertionResult.getExpression() ); - m_xml.scopedElement( "Expanded" ) - .writeText( assertionResult.getExpandedExpression() ); - } - - // And... Print a result applicable to each result type. - switch( assertionResult.getResultType() ) { - case ResultWas::ThrewException: - m_xml.scopedElement( "Exception" ) - .writeAttribute( "filename", assertionResult.getSourceInfo().file ) - .writeAttribute( "line", assertionResult.getSourceInfo().line ) - .writeText( assertionResult.getMessage() ); - break; - case ResultWas::FatalErrorCondition: - m_xml.scopedElement( "Fatal Error Condition" ) - .writeAttribute( "filename", assertionResult.getSourceInfo().file ) - .writeAttribute( "line", assertionResult.getSourceInfo().line ) - .writeText( assertionResult.getMessage() ); - break; - case ResultWas::Info: - m_xml.scopedElement( "Info" ) - .writeText( assertionResult.getMessage() ); - break; - case ResultWas::Warning: - // Warning will already have been written - break; - case ResultWas::ExplicitFailure: - m_xml.scopedElement( "Failure" ) - .writeText( assertionResult.getMessage() ); - break; - default: - break; - } - - if( assertionResult.hasExpression() ) - m_xml.endElement(); - - return true; - } - - virtual void sectionEnded( SectionStats const& sectionStats ) { - StreamingReporterBase::sectionEnded( sectionStats ); - if( --m_sectionDepth > 0 ) { - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); - e.writeAttribute( "successes", sectionStats.assertions.passed ); - e.writeAttribute( "failures", sectionStats.assertions.failed ); - e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); - - m_xml.endElement(); - } - } - - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { - StreamingReporterBase::testCaseEnded( testCaseStats ); - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); - e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); - - m_xml.endElement(); - } - - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { - StreamingReporterBase::testGroupEnded( testGroupStats ); - // TODO: Check testGroupStats.aborting and act accordingly. - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) - .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - virtual void testRunEnded( TestRunStats const& testRunStats ) { - StreamingReporterBase::testRunEnded( testRunStats ); - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testRunStats.totals.assertions.passed ) - .writeAttribute( "failures", testRunStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - private: - Timer m_testCaseTimer; - XmlWriter m_xml; - int m_sectionDepth; - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_junit.hpp -#define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED - -#include - -namespace Catch { - - class JunitReporter : public CumulativeReporterBase { - public: - JunitReporter( ReporterConfig const& _config ) - : CumulativeReporterBase( _config ), - xml( _config.stream() ) - {} - - ~JunitReporter(); - - static std::string getDescription() { - return "Reports test results in an XML format that looks like Ant's junitreport target"; - } - - virtual void noMatchingTestCases( std::string const& /*spec*/ ) {} - - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = true; - return prefs; - } - - virtual void testRunStarting( TestRunInfo const& runInfo ) { - CumulativeReporterBase::testRunStarting( runInfo ); - xml.startElement( "testsuites" ); - } - - virtual void testGroupStarting( GroupInfo const& groupInfo ) { - suiteTimer.start(); - stdOutForSuite.str(""); - stdErrForSuite.str(""); - unexpectedExceptions = 0; - CumulativeReporterBase::testGroupStarting( groupInfo ); - } - - virtual bool assertionEnded( AssertionStats const& assertionStats ) { - if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException ) - unexpectedExceptions++; - return CumulativeReporterBase::assertionEnded( assertionStats ); - } - - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { - stdOutForSuite << testCaseStats.stdOut; - stdErrForSuite << testCaseStats.stdErr; - CumulativeReporterBase::testCaseEnded( testCaseStats ); - } - - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) { - double suiteTime = suiteTimer.getElapsedSeconds(); - CumulativeReporterBase::testGroupEnded( testGroupStats ); - writeGroup( *m_testGroups.back(), suiteTime ); - } - - virtual void testRunEndedCumulative() { - xml.endElement(); - } - - void writeGroup( TestGroupNode const& groupNode, double suiteTime ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); - TestGroupStats const& stats = groupNode.value; - xml.writeAttribute( "name", stats.groupInfo.name ); - xml.writeAttribute( "errors", unexpectedExceptions ); - xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); - xml.writeAttribute( "tests", stats.totals.assertions.total() ); - xml.writeAttribute( "hostname", "tbd" ); // !TBD - if( m_config->showDurations() == ShowDurations::Never ) - xml.writeAttribute( "time", "" ); - else - xml.writeAttribute( "time", suiteTime ); - xml.writeAttribute( "timestamp", "tbd" ); // !TBD - - // Write test cases - for( TestGroupNode::ChildNodes::const_iterator - it = groupNode.children.begin(), itEnd = groupNode.children.end(); - it != itEnd; - ++it ) - writeTestCase( **it ); - - xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false ); - xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); - } - - void writeTestCase( TestCaseNode const& testCaseNode ) { - TestCaseStats const& stats = testCaseNode.value; - - // All test cases have exactly one section - which represents the - // test case itself. That section may have 0-n nested sections - assert( testCaseNode.children.size() == 1 ); - SectionNode const& rootSection = *testCaseNode.children.front(); - - std::string className = stats.testInfo.className; - - if( className.empty() ) { - if( rootSection.childSections.empty() ) - className = "global"; - } - writeSection( className, "", rootSection ); - } - - void writeSection( std::string const& className, - std::string const& rootName, - SectionNode const& sectionNode ) { - std::string name = trim( sectionNode.stats.sectionInfo.name ); - if( !rootName.empty() ) - name = rootName + "/" + name; - - if( !sectionNode.assertions.empty() || - !sectionNode.stdOut.empty() || - !sectionNode.stdErr.empty() ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); - if( className.empty() ) { - xml.writeAttribute( "classname", name ); - xml.writeAttribute( "name", "root" ); - } - else { - xml.writeAttribute( "classname", className ); - xml.writeAttribute( "name", name ); - } - xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) ); - - writeAssertions( sectionNode ); - - if( !sectionNode.stdOut.empty() ) - xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); - if( !sectionNode.stdErr.empty() ) - xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); - } - for( SectionNode::ChildSections::const_iterator - it = sectionNode.childSections.begin(), - itEnd = sectionNode.childSections.end(); - it != itEnd; - ++it ) - if( className.empty() ) - writeSection( name, "", **it ); - else - writeSection( className, name, **it ); - } - - void writeAssertions( SectionNode const& sectionNode ) { - for( SectionNode::Assertions::const_iterator - it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end(); - it != itEnd; - ++it ) - writeAssertion( *it ); - } - void writeAssertion( AssertionStats const& stats ) { - AssertionResult const& result = stats.assertionResult; - if( !result.isOk() ) { - std::string elementName; - switch( result.getResultType() ) { - case ResultWas::ThrewException: - case ResultWas::FatalErrorCondition: - elementName = "error"; - break; - case ResultWas::ExplicitFailure: - elementName = "failure"; - break; - case ResultWas::ExpressionFailed: - elementName = "failure"; - break; - case ResultWas::DidntThrowException: - elementName = "failure"; - break; - - // We should never see these here: - case ResultWas::Info: - case ResultWas::Warning: - case ResultWas::Ok: - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - elementName = "internalError"; - break; - } - - XmlWriter::ScopedElement e = xml.scopedElement( elementName ); - - xml.writeAttribute( "message", result.getExpandedExpression() ); - xml.writeAttribute( "type", result.getTestMacroName() ); - - std::ostringstream oss; - if( !result.getMessage().empty() ) - oss << result.getMessage() << "\n"; - for( std::vector::const_iterator - it = stats.infoMessages.begin(), - itEnd = stats.infoMessages.end(); - it != itEnd; - ++it ) - if( it->type == ResultWas::Info ) - oss << it->message << "\n"; - - oss << "at " << result.getSourceInfo(); - xml.writeText( oss.str(), false ); - } - } - - XmlWriter xml; - Timer suiteTimer; - std::ostringstream stdOutForSuite; - std::ostringstream stdErrForSuite; - unsigned int unexpectedExceptions; - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_console.hpp -#define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED - -namespace Catch { - - struct ConsoleReporter : StreamingReporterBase { - ConsoleReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ), - m_headerPrinted( false ) - {} - - virtual ~ConsoleReporter(); - static std::string getDescription() { - return "Reports test results as plain lines of text"; - } - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = false; - return prefs; - } - - virtual void noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << "'" << std::endl; - } - - virtual void assertionStarting( AssertionInfo const& ) { - } - - virtual bool assertionEnded( AssertionStats const& _assertionStats ) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool printInfoMessages = true; - - // Drop out if result was successful and we're not printing those - if( !m_config->includeSuccessfulResults() && result.isOk() ) { - if( result.getResultType() != ResultWas::Warning ) - return false; - printInfoMessages = false; - } - - lazyPrint(); - - AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); - printer.print(); - stream << std::endl; - return true; - } - - virtual void sectionStarting( SectionInfo const& _sectionInfo ) { - m_headerPrinted = false; - StreamingReporterBase::sectionStarting( _sectionInfo ); - } - virtual void sectionEnded( SectionStats const& _sectionStats ) { - if( _sectionStats.missingAssertions ) { - lazyPrint(); - Colour colour( Colour::ResultError ); - if( m_sectionStack.size() > 1 ) - stream << "\nNo assertions in section"; - else - stream << "\nNo assertions in test case"; - stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; - } - if( m_headerPrinted ) { - if( m_config->showDurations() == ShowDurations::Always ) - stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl; - m_headerPrinted = false; - } - else { - if( m_config->showDurations() == ShowDurations::Always ) - stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl; - } - StreamingReporterBase::sectionEnded( _sectionStats ); - } - - virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) { - StreamingReporterBase::testCaseEnded( _testCaseStats ); - m_headerPrinted = false; - } - virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) { - if( currentGroupInfo.used ) { - printSummaryDivider(); - stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; - printTotals( _testGroupStats.totals ); - stream << "\n" << std::endl; - } - StreamingReporterBase::testGroupEnded( _testGroupStats ); - } - virtual void testRunEnded( TestRunStats const& _testRunStats ) { - printTotalsDivider( _testRunStats.totals ); - printTotals( _testRunStats.totals ); - stream << std::endl; - StreamingReporterBase::testRunEnded( _testRunStats ); - } - - private: - - class AssertionPrinter { - void operator= ( AssertionPrinter const& ); - public: - AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) - : stream( _stream ), - stats( _stats ), - result( _stats.assertionResult ), - colour( Colour::None ), - message( result.getMessage() ), - messages( _stats.infoMessages ), - printInfoMessages( _printInfoMessages ) - { - switch( result.getResultType() ) { - case ResultWas::Ok: - colour = Colour::Success; - passOrFail = "PASSED"; - //if( result.hasMessage() ) - if( _stats.infoMessages.size() == 1 ) - messageLabel = "with message"; - if( _stats.infoMessages.size() > 1 ) - messageLabel = "with messages"; - break; - case ResultWas::ExpressionFailed: - if( result.isOk() ) { - colour = Colour::Success; - passOrFail = "FAILED - but was ok"; - } - else { - colour = Colour::Error; - passOrFail = "FAILED"; - } - if( _stats.infoMessages.size() == 1 ) - messageLabel = "with message"; - if( _stats.infoMessages.size() > 1 ) - messageLabel = "with messages"; - break; - case ResultWas::ThrewException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to unexpected exception with message"; - break; - case ResultWas::FatalErrorCondition: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to a fatal error condition"; - break; - case ResultWas::DidntThrowException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "because no exception was thrown where one was expected"; - break; - case ResultWas::Info: - messageLabel = "info"; - break; - case ResultWas::Warning: - messageLabel = "warning"; - break; - case ResultWas::ExplicitFailure: - passOrFail = "FAILED"; - colour = Colour::Error; - if( _stats.infoMessages.size() == 1 ) - messageLabel = "explicitly with message"; - if( _stats.infoMessages.size() > 1 ) - messageLabel = "explicitly with messages"; - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - passOrFail = "** internal error **"; - colour = Colour::Error; - break; - } - } - - void print() const { - printSourceInfo(); - if( stats.totals.assertions.total() > 0 ) { - if( result.isOk() ) - stream << "\n"; - printResultType(); - printOriginalExpression(); - printReconstructedExpression(); - } - else { - stream << "\n"; - } - printMessage(); - } - - private: - void printResultType() const { - if( !passOrFail.empty() ) { - Colour colourGuard( colour ); - stream << passOrFail << ":\n"; - } - } - void printOriginalExpression() const { - if( result.hasExpression() ) { - Colour colourGuard( Colour::OriginalExpression ); - stream << " "; - stream << result.getExpressionInMacro(); - stream << "\n"; - } - } - void printReconstructedExpression() const { - if( result.hasExpandedExpression() ) { - stream << "with expansion:\n"; - Colour colourGuard( Colour::ReconstructedExpression ); - stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n"; - } - } - void printMessage() const { - if( !messageLabel.empty() ) - stream << messageLabel << ":" << "\n"; - for( std::vector::const_iterator it = messages.begin(), itEnd = messages.end(); - it != itEnd; - ++it ) { - // If this assertion is a warning ignore any INFO messages - if( printInfoMessages || it->type != ResultWas::Info ) - stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n"; - } - } - void printSourceInfo() const { - Colour colourGuard( Colour::FileName ); - stream << result.getSourceInfo() << ": "; - } - - std::ostream& stream; - AssertionStats const& stats; - AssertionResult const& result; - Colour::Code colour; - std::string passOrFail; - std::string messageLabel; - std::string message; - std::vector messages; - bool printInfoMessages; - }; - - void lazyPrint() { - - if( !currentTestRunInfo.used ) - lazyPrintRunInfo(); - if( !currentGroupInfo.used ) - lazyPrintGroupInfo(); - - if( !m_headerPrinted ) { - printTestCaseAndSectionHeader(); - m_headerPrinted = true; - } - } - void lazyPrintRunInfo() { - stream << "\n" << getLineOfChars<'~'>() << "\n"; - Colour colour( Colour::SecondaryText ); - stream << currentTestRunInfo->name - << " is a Catch v" << libraryVersion << " host application.\n" - << "Run with -? for options\n\n"; - - if( m_config->rngSeed() != 0 ) - stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; - - currentTestRunInfo.used = true; - } - void lazyPrintGroupInfo() { - if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) { - printClosedHeader( "Group: " + currentGroupInfo->name ); - currentGroupInfo.used = true; - } - } - void printTestCaseAndSectionHeader() { - assert( !m_sectionStack.empty() ); - printOpenHeader( currentTestCaseInfo->name ); - - if( m_sectionStack.size() > 1 ) { - Colour colourGuard( Colour::Headers ); - - std::vector::const_iterator - it = m_sectionStack.begin()+1, // Skip first section (test case) - itEnd = m_sectionStack.end(); - for( ; it != itEnd; ++it ) - printHeaderString( it->name, 2 ); - } - - SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; - - if( !lineInfo.empty() ){ - stream << getLineOfChars<'-'>() << "\n"; - Colour colourGuard( Colour::FileName ); - stream << lineInfo << "\n"; - } - stream << getLineOfChars<'.'>() << "\n" << std::endl; - } - - void printClosedHeader( std::string const& _name ) { - printOpenHeader( _name ); - stream << getLineOfChars<'.'>() << "\n"; - } - void printOpenHeader( std::string const& _name ) { - stream << getLineOfChars<'-'>() << "\n"; - { - Colour colourGuard( Colour::Headers ); - printHeaderString( _name ); - } - } - - // if string has a : in first line will set indent to follow it on - // subsequent lines - void printHeaderString( std::string const& _string, std::size_t indent = 0 ) { - std::size_t i = _string.find( ": " ); - if( i != std::string::npos ) - i+=2; - else - i = 0; - stream << Text( _string, TextAttributes() - .setIndent( indent+i) - .setInitialIndent( indent ) ) << "\n"; - } - - struct SummaryColumn { - - SummaryColumn( std::string const& _label, Colour::Code _colour ) - : label( _label ), - colour( _colour ) - {} - SummaryColumn addRow( std::size_t count ) { - std::ostringstream oss; - oss << count; - std::string row = oss.str(); - for( std::vector::iterator it = rows.begin(); it != rows.end(); ++it ) { - while( it->size() < row.size() ) - *it = " " + *it; - while( it->size() > row.size() ) - row = " " + row; - } - rows.push_back( row ); - return *this; - } - - std::string label; - Colour::Code colour; - std::vector rows; - - }; - - void printTotals( Totals const& totals ) { - if( totals.testCases.total() == 0 ) { - stream << Colour( Colour::Warning ) << "No tests ran\n"; - } - else if( totals.assertions.total() > 0 && totals.assertions.allPassed() ) { - stream << Colour( Colour::ResultSuccess ) << "All tests passed"; - stream << " (" - << pluralise( totals.assertions.passed, "assertion" ) << " in " - << pluralise( totals.testCases.passed, "test case" ) << ")" - << "\n"; - } - else { - - std::vector columns; - columns.push_back( SummaryColumn( "", Colour::None ) - .addRow( totals.testCases.total() ) - .addRow( totals.assertions.total() ) ); - columns.push_back( SummaryColumn( "passed", Colour::Success ) - .addRow( totals.testCases.passed ) - .addRow( totals.assertions.passed ) ); - columns.push_back( SummaryColumn( "failed", Colour::ResultError ) - .addRow( totals.testCases.failed ) - .addRow( totals.assertions.failed ) ); - columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure ) - .addRow( totals.testCases.failedButOk ) - .addRow( totals.assertions.failedButOk ) ); - - printSummaryRow( "test cases", columns, 0 ); - printSummaryRow( "assertions", columns, 1 ); - } - } - void printSummaryRow( std::string const& label, std::vector const& cols, std::size_t row ) { - for( std::vector::const_iterator it = cols.begin(); it != cols.end(); ++it ) { - std::string value = it->rows[row]; - if( it->label.empty() ) { - stream << label << ": "; - if( value != "0" ) - stream << value; - else - stream << Colour( Colour::Warning ) << "- none -"; - } - else if( value != "0" ) { - stream << Colour( Colour::LightGrey ) << " | "; - stream << Colour( it->colour ) - << value << " " << it->label; - } - } - stream << "\n"; - } - - static std::size_t makeRatio( std::size_t number, std::size_t total ) { - std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; - return ( ratio == 0 && number > 0 ) ? 1 : ratio; - } - static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { - if( i > j && i > k ) - return i; - else if( j > k ) - return j; - else - return k; - } - - void printTotalsDivider( Totals const& totals ) { - if( totals.testCases.total() > 0 ) { - std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() ); - std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() ); - std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() ); - while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 ) - findMax( failedRatio, failedButOkRatio, passedRatio )++; - while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 ) - findMax( failedRatio, failedButOkRatio, passedRatio )--; - - stream << Colour( Colour::Error ) << std::string( failedRatio, '=' ); - stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' ); - if( totals.testCases.allPassed() ) - stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' ); - else - stream << Colour( Colour::Success ) << std::string( passedRatio, '=' ); - } - else { - stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); - } - stream << "\n"; - } - void printSummaryDivider() { - stream << getLineOfChars<'-'>() << "\n"; - } - - private: - bool m_headerPrinted; - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter ) - -} // end namespace Catch - -// #included from: ../reporters/catch_reporter_compact.hpp -#define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED - -namespace Catch { - - struct CompactReporter : StreamingReporterBase { - - CompactReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ) - {} - - virtual ~CompactReporter(); - - static std::string getDescription() { - return "Reports test results on a single line, suitable for IDEs"; - } - - virtual ReporterPreferences getPreferences() const { - ReporterPreferences prefs; - prefs.shouldRedirectStdOut = false; - return prefs; - } - - virtual void noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << "'" << std::endl; - } - - virtual void assertionStarting( AssertionInfo const& ) { - } - - virtual bool assertionEnded( AssertionStats const& _assertionStats ) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool printInfoMessages = true; - - // Drop out if result was successful and we're not printing those - if( !m_config->includeSuccessfulResults() && result.isOk() ) { - if( result.getResultType() != ResultWas::Warning ) - return false; - printInfoMessages = false; - } - - AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); - printer.print(); - - stream << std::endl; - return true; - } - - virtual void testRunEnded( TestRunStats const& _testRunStats ) { - printTotals( _testRunStats.totals ); - stream << "\n" << std::endl; - StreamingReporterBase::testRunEnded( _testRunStats ); - } - - private: - class AssertionPrinter { - void operator= ( AssertionPrinter const& ); - public: - AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) - : stream( _stream ) - , stats( _stats ) - , result( _stats.assertionResult ) - , messages( _stats.infoMessages ) - , itMessage( _stats.infoMessages.begin() ) - , printInfoMessages( _printInfoMessages ) - {} - - void print() { - printSourceInfo(); - - itMessage = messages.begin(); - - switch( result.getResultType() ) { - case ResultWas::Ok: - printResultType( Colour::ResultSuccess, passedString() ); - printOriginalExpression(); - printReconstructedExpression(); - if ( ! result.hasExpression() ) - printRemainingMessages( Colour::None ); - else - printRemainingMessages(); - break; - case ResultWas::ExpressionFailed: - if( result.isOk() ) - printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) ); - else - printResultType( Colour::Error, failedString() ); - printOriginalExpression(); - printReconstructedExpression(); - printRemainingMessages(); - break; - case ResultWas::ThrewException: - printResultType( Colour::Error, failedString() ); - printIssue( "unexpected exception with message:" ); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::FatalErrorCondition: - printResultType( Colour::Error, failedString() ); - printIssue( "fatal error condition with message:" ); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::DidntThrowException: - printResultType( Colour::Error, failedString() ); - printIssue( "expected exception, got none" ); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::Info: - printResultType( Colour::None, "info" ); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::Warning: - printResultType( Colour::None, "warning" ); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::ExplicitFailure: - printResultType( Colour::Error, failedString() ); - printIssue( "explicitly" ); - printRemainingMessages( Colour::None ); - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - printResultType( Colour::Error, "** internal error **" ); - break; - } - } - - private: - // Colour::LightGrey - - static Colour::Code dimColour() { return Colour::FileName; } - -#ifdef CATCH_PLATFORM_MAC - static const char* failedString() { return "FAILED"; } - static const char* passedString() { return "PASSED"; } -#else - static const char* failedString() { return "failed"; } - static const char* passedString() { return "passed"; } -#endif - - void printSourceInfo() const { - Colour colourGuard( Colour::FileName ); - stream << result.getSourceInfo() << ":"; - } - - void printResultType( Colour::Code colour, std::string passOrFail ) const { - if( !passOrFail.empty() ) { - { - Colour colourGuard( colour ); - stream << " " << passOrFail; - } - stream << ":"; - } - } - - void printIssue( std::string issue ) const { - stream << " " << issue; - } - - void printExpressionWas() { - if( result.hasExpression() ) { - stream << ";"; - { - Colour colour( dimColour() ); - stream << " expression was:"; - } - printOriginalExpression(); - } - } - - void printOriginalExpression() const { - if( result.hasExpression() ) { - stream << " " << result.getExpression(); - } - } - - void printReconstructedExpression() const { - if( result.hasExpandedExpression() ) { - { - Colour colour( dimColour() ); - stream << " for: "; - } - stream << result.getExpandedExpression(); - } - } - - void printMessage() { - if ( itMessage != messages.end() ) { - stream << " '" << itMessage->message << "'"; - ++itMessage; - } - } - - void printRemainingMessages( Colour::Code colour = dimColour() ) { - if ( itMessage == messages.end() ) - return; - - // using messages.end() directly yields compilation error: - std::vector::const_iterator itEnd = messages.end(); - const std::size_t N = static_cast( std::distance( itMessage, itEnd ) ); - - { - Colour colourGuard( colour ); - stream << " with " << pluralise( N, "message" ) << ":"; - } - - for(; itMessage != itEnd; ) { - // If this assertion is a warning ignore any INFO messages - if( printInfoMessages || itMessage->type != ResultWas::Info ) { - stream << " '" << itMessage->message << "'"; - if ( ++itMessage != itEnd ) { - Colour colourGuard( dimColour() ); - stream << " and"; - } - } - } - } - - private: - std::ostream& stream; - AssertionStats const& stats; - AssertionResult const& result; - std::vector messages; - std::vector::const_iterator itMessage; - bool printInfoMessages; - }; - - // Colour, message variants: - // - white: No tests ran. - // - red: Failed [both/all] N test cases, failed [both/all] M assertions. - // - white: Passed [both/all] N test cases (no assertions). - // - red: Failed N tests cases, failed M assertions. - // - green: Passed [both/all] N tests cases with M assertions. - - std::string bothOrAll( std::size_t count ) const { - return count == 1 ? "" : count == 2 ? "both " : "all " ; - } - - void printTotals( const Totals& totals ) const { - if( totals.testCases.total() == 0 ) { - stream << "No tests ran."; - } - else if( totals.testCases.failed == totals.testCases.total() ) { - Colour colour( Colour::ResultError ); - const std::string qualify_assertions_failed = - totals.assertions.failed == totals.assertions.total() ? - bothOrAll( totals.assertions.failed ) : ""; - stream << - "Failed " << bothOrAll( totals.testCases.failed ) - << pluralise( totals.testCases.failed, "test case" ) << ", " - "failed " << qualify_assertions_failed << - pluralise( totals.assertions.failed, "assertion" ) << "."; - } - else if( totals.assertions.total() == 0 ) { - stream << - "Passed " << bothOrAll( totals.testCases.total() ) - << pluralise( totals.testCases.total(), "test case" ) - << " (no assertions)."; - } - else if( totals.assertions.failed ) { - Colour colour( Colour::ResultError ); - stream << - "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", " - "failed " << pluralise( totals.assertions.failed, "assertion" ) << "."; - } - else { - Colour colour( Colour::ResultSuccess ); - stream << - "Passed " << bothOrAll( totals.testCases.passed ) - << pluralise( totals.testCases.passed, "test case" ) << - " with " << pluralise( totals.assertions.passed, "assertion" ) << "."; - } - } - }; - - INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter ) - -} // end namespace Catch - -namespace Catch { - NonCopyable::~NonCopyable() {} - IShared::~IShared() {} - StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {} - IContext::~IContext() {} - IResultCapture::~IResultCapture() {} - ITestCase::~ITestCase() {} - ITestCaseRegistry::~ITestCaseRegistry() {} - IRegistryHub::~IRegistryHub() {} - IMutableRegistryHub::~IMutableRegistryHub() {} - IExceptionTranslator::~IExceptionTranslator() {} - IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {} - IReporter::~IReporter() {} - IReporterFactory::~IReporterFactory() {} - IReporterRegistry::~IReporterRegistry() {} - IStreamingReporter::~IStreamingReporter() {} - AssertionStats::~AssertionStats() {} - SectionStats::~SectionStats() {} - TestCaseStats::~TestCaseStats() {} - TestGroupStats::~TestGroupStats() {} - TestRunStats::~TestRunStats() {} - CumulativeReporterBase::SectionNode::~SectionNode() {} - CumulativeReporterBase::~CumulativeReporterBase() {} - - StreamingReporterBase::~StreamingReporterBase() {} - ConsoleReporter::~ConsoleReporter() {} - CompactReporter::~CompactReporter() {} - IRunner::~IRunner() {} - IMutableContext::~IMutableContext() {} - IConfig::~IConfig() {} - XmlReporter::~XmlReporter() {} - JunitReporter::~JunitReporter() {} - TestRegistry::~TestRegistry() {} - FreeFunctionTestCase::~FreeFunctionTestCase() {} - IGeneratorInfo::~IGeneratorInfo() {} - IGeneratorsForTest::~IGeneratorsForTest() {} - TestSpec::Pattern::~Pattern() {} - TestSpec::NamePattern::~NamePattern() {} - TestSpec::TagPattern::~TagPattern() {} - TestSpec::ExcludedPattern::~ExcludedPattern() {} - - Matchers::Impl::StdString::Equals::~Equals() {} - Matchers::Impl::StdString::Contains::~Contains() {} - Matchers::Impl::StdString::StartsWith::~StartsWith() {} - Matchers::Impl::StdString::EndsWith::~EndsWith() {} - - void Config::dummy() {} -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -#endif - -#ifdef CATCH_CONFIG_MAIN -// #included from: internal/catch_default_main.hpp -#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED - -#ifndef __OBJC__ - -// Standard C/C++ main entry point -int main (int argc, char * const argv[]) { - return Catch::Session().run( argc, argv ); -} - -#else // __OBJC__ - -// Objective-C entry point -int main (int argc, char * const argv[]) { -#if !CATCH_ARC_ENABLED - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; -#endif - - Catch::registerTestMethods(); - int result = Catch::Session().run( argc, (char* const*)argv ); - -#if !CATCH_ARC_ENABLED - [pool drain]; -#endif - - return result; -} - -#endif // __OBJC__ - -#endif - -#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED -# undef CLARA_CONFIG_MAIN -#endif - -////// - -// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ -#ifdef CATCH_CONFIG_PREFIX_ALL - -#define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" ) -#define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "CATCH_REQUIRE_FALSE" ) - -#define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS" ) -#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" ) -#define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" ) - -#define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" ) -#define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CATCH_CHECK_FALSE" ) -#define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" ) -#define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" ) -#define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" ) - -#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" ) -#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" ) -#define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" ) - -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" ) -#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" ) - -#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) -#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg ) -#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) -#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) -#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) - #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) - #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) - #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) - #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ ) - #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ ) -#else - #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) - #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) - #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) - #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) - #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg ) - #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg ) -#endif -#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) - -#define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) -#define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) - -#define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) - -// "BDD-style" convenience wrappers -#ifdef CATCH_CONFIG_VARIADIC_MACROS -#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#else -#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags ) -#define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) -#endif -#define CATCH_GIVEN( desc ) CATCH_SECTION( "Given: " desc, "" ) -#define CATCH_WHEN( desc ) CATCH_SECTION( " When: " desc, "" ) -#define CATCH_AND_WHEN( desc ) CATCH_SECTION( " And: " desc, "" ) -#define CATCH_THEN( desc ) CATCH_SECTION( " Then: " desc, "" ) -#define CATCH_AND_THEN( desc ) CATCH_SECTION( " And: " desc, "" ) - -// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required -#else - -#define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" ) -#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "REQUIRE_FALSE" ) - -#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "REQUIRE_THROWS" ) -#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" ) -#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" ) - -#define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" ) -#define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CHECK_FALSE" ) -#define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" ) -#define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" ) -#define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" ) - -#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS" ) -#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" ) -#define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" ) - -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" ) -#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" ) - -#define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) -#define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg ) -#define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) -#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) -#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) - -#ifdef CATCH_CONFIG_VARIADIC_MACROS - #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) - #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) - #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) - #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) - #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ ) - #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ ) -#else - #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) - #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) - #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) - #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) - #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg ) - #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg ) -#endif -#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) - -#define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) -#define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) - -#define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) - -#endif - -#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) - -// "BDD-style" convenience wrappers -#ifdef CATCH_CONFIG_VARIADIC_MACROS -#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#else -#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags ) -#define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) -#endif -#define GIVEN( desc ) SECTION( " Given: " desc, "" ) -#define WHEN( desc ) SECTION( " When: " desc, "" ) -#define AND_WHEN( desc ) SECTION( "And when: " desc, "" ) -#define THEN( desc ) SECTION( " Then: " desc, "" ) -#define AND_THEN( desc ) SECTION( " And: " desc, "" ) - -using Catch::Detail::Approx; - -// #included from: internal/catch_reenable_warnings.h - -#define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(pop) -# else -# pragma clang diagnostic pop -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic pop -#endif - -#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED - diff --git a/third_party/libosmium/test/include/utils.hpp b/third_party/libosmium/test/include/utils.hpp deleted file mode 100644 index 662155abf..000000000 --- a/third_party/libosmium/test/include/utils.hpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include -#include - -inline std::string with_data_dir(const char* filename) { - const char* data_dir = getenv("OSMIUM_TEST_DATA_DIR"); - - std::string result; - if (data_dir) { - result = data_dir; - result += '/'; - } - - result += filename; - - return result; -} - diff --git a/third_party/libosmium/test/include/win_mkstemp.hpp b/third_party/libosmium/test/include/win_mkstemp.hpp deleted file mode 100644 index 693c266f3..000000000 --- a/third_party/libosmium/test/include/win_mkstemp.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * mkstemp.c - * - * Provides a trivial replacement for the POSIX `mkstemp()' function, - * suitable for use in MinGW (Win32) applications. - * - * This file is part of the MinGW32 package set. - * - * Contributed by Keith Marshall - * Patched to VS2013 by alex85k - * THIS SOFTWARE IS NOT COPYRIGHTED - * - * This source code is offered for use in the public domain. You may - * use, modify or distribute it freely. - * - * This code is distributed in the hope that it will be useful but - * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY - * DISCLAIMED. This includes but is not limited to warranties of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ - -#ifndef WIN_MKSTEMP_H -#define WIN_MKSTEMP_H - -#include -#include -#include - -inline int mkstemp( char *templ ) -{ - int maxtry = 26, rtn = -1; - - while( maxtry-- && (rtn < 0) ) - { - char *r = _mktemp( templ ); - if( r == NULL ) - return -1; - rtn = sopen( r, O_RDWR | O_CREAT | O_EXCL | O_BINARY, SH_DENYRW, 0600 ); - } - return rtn; -} -#endif diff --git a/third_party/libosmium/test/t/area/test_area_id.cpp b/third_party/libosmium/test/t/area/test_area_id.cpp deleted file mode 100644 index fbd8d784c..000000000 --- a/third_party/libosmium/test/t/area/test_area_id.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("area_id") { - - SECTION("object_id_to_area_id_conversion") { - REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way)); - REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation)); - REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way)); - REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation)); - REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way)); - REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation)); - } - - SECTION("area_id_to_object_id_conversion") { - REQUIRE( 23 == osmium::area_id_to_object_id( 46)); - REQUIRE( 23 == osmium::area_id_to_object_id( 47)); - REQUIRE( 0 == osmium::area_id_to_object_id( 0)); - REQUIRE( 0 == osmium::area_id_to_object_id( 1)); - REQUIRE(-12 == osmium::area_id_to_object_id(-24)); - REQUIRE(-12 == osmium::area_id_to_object_id(-25)); - } - -} diff --git a/third_party/libosmium/test/t/area/test_node_ref_segment.cpp b/third_party/libosmium/test/t/area/test_node_ref_segment.cpp deleted file mode 100644 index 3261c24e1..000000000 --- a/third_party/libosmium/test/t/area/test_node_ref_segment.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "catch.hpp" - -#include - -using osmium::area::detail::NodeRefSegment; - -TEST_CASE("NodeRefSegmentClass") { - - SECTION("instantiation_with_default_parameters") { - NodeRefSegment s; - REQUIRE(s.first().ref() == 0); - REQUIRE(s.first().location() == osmium::Location()); - REQUIRE(s.second().ref() == 0); - REQUIRE(s.second().location() == osmium::Location()); - } - - SECTION("instantiation") { - osmium::NodeRef nr1(1, { 1.2, 3.4 }); - osmium::NodeRef nr2(2, { 1.4, 3.1 }); - osmium::NodeRef nr3(3, { 1.2, 3.6 }); - osmium::NodeRef nr4(4, { 1.2, 3.7 }); - - NodeRefSegment s1(nr1, nr2, nullptr, nullptr); - REQUIRE(s1.first().ref() == 1); - REQUIRE(s1.second().ref() == 2); - - NodeRefSegment s2(nr2, nr3, nullptr, nullptr); - REQUIRE(s2.first().ref() == 3); - REQUIRE(s2.second().ref() == 2); - - NodeRefSegment s3(nr3, nr4, nullptr, nullptr); - REQUIRE(s3.first().ref() == 3); - REQUIRE(s3.second().ref() == 4); - } - - SECTION("intersection") { - NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr); - NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr); - NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr); - NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr); - NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr); - NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr); - NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr); - - REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0)); - REQUIRE(calculate_intersection(s1, s3) == osmium::Location()); - REQUIRE(calculate_intersection(s2, s3) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s4) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0)); - REQUIRE(calculate_intersection(s1, s1) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s6) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s7) == osmium::Location()); - } - - SECTION("intersection of very long segments") { - NodeRefSegment s1({ 1, {90.0, 90.0}}, { 2, {-90.0, -90.0}}, nullptr, nullptr); - NodeRefSegment s2({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}}, nullptr, nullptr); - REQUIRE(calculate_intersection(s1, s2) == osmium::Location(0.0, 0.0)); - - NodeRefSegment s3({ 1, {-90.0, -90.0}}, { 2, {90.0, 90.0}}, nullptr, nullptr); - NodeRefSegment s4({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}}, nullptr, nullptr); - REQUIRE(calculate_intersection(s3, s4) == osmium::Location(0.0, 0.0)); - - NodeRefSegment s5({ 1, {-90.0000001, -90.0}}, { 2, {90.0, 90.0}}, nullptr, nullptr); - NodeRefSegment s6({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}}, nullptr, nullptr); - REQUIRE(calculate_intersection(s5, s6) == osmium::Location(0.0, 0.0)); - } - - SECTION("to_left_of") { - osmium::Location loc { 2.0, 2.0 }; - - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - - REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false); - } - - SECTION("ordering") { - osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); - osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); - osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); - osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); - - REQUIRE(node_ref1 < node_ref2); - REQUIRE(node_ref2 < node_ref3); - REQUIRE(node_ref1 < node_ref3); - REQUIRE(node_ref1 >= node_ref1); - - REQUIRE( osmium::location_less()(node_ref1, node_ref2)); - REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); - REQUIRE( osmium::location_less()(node_ref1, node_ref3)); - REQUIRE( osmium::location_less()(node_ref3, node_ref4)); - REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); - } - -} - diff --git a/third_party/libosmium/test/t/basic/helper.hpp b/third_party/libosmium/test/t/basic/helper.hpp deleted file mode 100644 index 5a2130e4e..000000000 --- a/third_party/libosmium/test/t/basic/helper.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef TEST_BASIC_HELPER_HPP -#define TEST_BASIC_HELPER_HPP - -#include -#include -#include - -#include - -inline void add_tags(osmium::memory::Buffer& buffer, osmium::builder::Builder& builder, const std::vector>& tags) { - osmium::builder::TagListBuilder tl_builder(buffer, &builder); - for (const auto& tag : tags) { - tl_builder.add_tag(tag.first, tag.second); - } -} - -inline osmium::Node& buffer_add_node(osmium::memory::Buffer& buffer, const char* user, const std::vector>& tags, const osmium::Location& location) { - osmium::builder::NodeBuilder builder(buffer); - builder.add_user(user); - add_tags(buffer, builder, tags); - buffer.commit(); - return builder.object().set_location(location); -} - -inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* user, const std::vector>& tags, const std::vector& nodes) { - osmium::builder::WayBuilder builder(buffer); - builder.add_user(user); - add_tags(buffer, builder, tags); - { - osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder); - for (const osmium::object_id_type ref : nodes) { - wnl_builder.add_node_ref(ref); - } - } - buffer.commit(); - return builder.object(); -} - -inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* user, const std::vector>& tags, const std::vector>& nodes) { - osmium::builder::WayBuilder builder(buffer); - builder.add_user(user); - add_tags(buffer, builder, tags); - { - osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder); - for (const auto& p : nodes) { - wnl_builder.add_node_ref(p.first, p.second); - } - } - buffer.commit(); - return builder.object(); -} - -inline osmium::Relation& buffer_add_relation( - osmium::memory::Buffer& buffer, - const char* user, - const std::vector>& tags, const std::vector>& members) { - osmium::builder::RelationBuilder builder(buffer); - builder.add_user(user); - add_tags(buffer, builder, tags); - { - osmium::builder::RelationMemberListBuilder rml_builder(buffer, &builder); - for (const auto& member : members) { - rml_builder.add_member(osmium::char_to_item_type(std::get<0>(member)), std::get<1>(member), std::get<2>(member)); - } - } - buffer.commit(); - return builder.object(); -} - -inline osmium::Area& buffer_add_area(osmium::memory::Buffer& buffer, const char* user, - const std::vector>& tags, - const std::vector>>>& rings) { - osmium::builder::AreaBuilder builder(buffer); - builder.add_user(user); - add_tags(buffer, builder, tags); - - for (const auto& ring : rings) { - if (ring.first) { - osmium::builder::OuterRingBuilder ring_builder(buffer, &builder); - for (const auto& p : ring.second) { - ring_builder.add_node_ref(p.first, p.second); - } - } else { - osmium::builder::InnerRingBuilder ring_builder(buffer, &builder); - for (const auto& p : ring.second) { - ring_builder.add_node_ref(p.first, p.second); - } - } - } - buffer.commit(); - return builder.object(); -} - -inline osmium::Changeset& buffer_add_changeset(osmium::memory::Buffer& buffer, const char* user, const std::vector>& tags) { - osmium::builder::ChangesetBuilder builder(buffer); - builder.add_user(user); - add_tags(buffer, builder, tags); - buffer.commit(); - return builder.object(); -} - -#endif // TEST_BASIC_HELPER_HPP diff --git a/third_party/libosmium/test/t/basic/test_box.cpp b/third_party/libosmium/test/t/basic/test_box.cpp deleted file mode 100644 index 768cf41f3..000000000 --- a/third_party/libosmium/test/t/basic/test_box.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -#include -#include -#include - -TEST_CASE("Box") { - - SECTION("instantiation") { - osmium::Box b; - REQUIRE(!b); - REQUIRE(!b.bottom_left()); - REQUIRE(!b.top_right()); - REQUIRE_THROWS_AS(b.size(), osmium::invalid_location); - } - - SECTION("instantiation_and_extend_with_undefined") { - osmium::Box b; - REQUIRE(!b); - b.extend(osmium::Location()); - REQUIRE(!b.bottom_left()); - REQUIRE(!b.top_right()); - } - - SECTION("instantiation_and_extend") { - osmium::Box b; - osmium::Location loc1 { 1.2, 3.4 }; - b.extend(loc1); - REQUIRE(!!b); - REQUIRE(!!b.bottom_left()); - REQUIRE(!!b.top_right()); - REQUIRE(b.contains(loc1)); - - osmium::Location loc2 { 3.4, 4.5 }; - osmium::Location loc3 { 5.6, 7.8 }; - - b.extend(loc2); - b.extend(loc3); - REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4)); - REQUIRE(b.top_right() == osmium::Location(5.6, 7.8)); - - // extend with undefined doesn't change anything - b.extend(osmium::Location()); - REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4)); - REQUIRE(b.top_right() == osmium::Location(5.6, 7.8)); - - REQUIRE(b.contains(loc1)); - REQUIRE(b.contains(loc2)); - REQUIRE(b.contains(loc3)); - - osmium::CRC crc32; - crc32.update(b); - REQUIRE(crc32().checksum() == 0xd381a838); - } - - SECTION("output_defined") { - osmium::Box b; - b.extend(osmium::Location(1.2, 3.4)); - b.extend(osmium::Location(5.6, 7.8)); - std::stringstream out; - out << b; - REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)"); - REQUIRE(b.size() == Approx(19.36).epsilon(0.000001)); - } - - SECTION("output_undefined") { - osmium::Box b; - std::stringstream out; - out << b; - REQUIRE(out.str() == "(undefined)"); - } - - SECTION("box_inside_box") { - osmium::Box outer; - outer.extend(osmium::Location(1, 1)); - outer.extend(osmium::Location(10, 10)); - - osmium::Box inner; - inner.extend(osmium::Location(2, 2)); - inner.extend(osmium::Location(4, 4)); - - osmium::Box overlap; - overlap.extend(osmium::Location(3, 3)); - overlap.extend(osmium::Location(5, 5)); - - REQUIRE( osmium::geom::contains(inner, outer)); - REQUIRE(!osmium::geom::contains(outer, inner)); - - REQUIRE(!osmium::geom::contains(overlap, inner)); - REQUIRE(!osmium::geom::contains(inner, overlap)); - } - -} - diff --git a/third_party/libosmium/test/t/basic/test_changeset.cpp b/third_party/libosmium/test/t/basic/test_changeset.cpp deleted file mode 100644 index d1f3fde87..000000000 --- a/third_party/libosmium/test/t/basic/test_changeset.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include - -#include "helper.hpp" - -TEST_CASE("Basic Changeset") { - - osmium::CRC crc32; - - osmium::memory::Buffer buffer(10 * 1000); - - osmium::Changeset& cs1 = buffer_add_changeset(buffer, - "user", - {{"comment", "foo"}}); - - cs1.set_id(42) - .set_created_at(100) - .set_closed_at(200) - .set_num_changes(7) - .set_num_comments(3) - .set_uid(9); - - REQUIRE(42 == cs1.id()); - REQUIRE(9 == cs1.uid()); - REQUIRE(7 == cs1.num_changes()); - REQUIRE(3 == cs1.num_comments()); - REQUIRE(true == cs1.closed()); - REQUIRE(osmium::Timestamp(100) == cs1.created_at()); - REQUIRE(osmium::Timestamp(200) == cs1.closed_at()); - REQUIRE(1 == cs1.tags().size()); - REQUIRE(std::string("user") == cs1.user()); - - crc32.update(cs1); - REQUIRE(crc32().checksum() == 0x502e8c0e); - - osmium::Changeset& cs2 = buffer_add_changeset(buffer, - "user", - {{"comment", "foo"}, {"foo", "bar"}}); - - cs2.set_id(43) - .set_created_at(120) - .set_num_changes(21) - .set_num_comments(osmium::num_comments_type(0)) - .set_uid(9); - - REQUIRE(43 == cs2.id()); - REQUIRE(9 == cs2.uid()); - REQUIRE(21 == cs2.num_changes()); - REQUIRE(0 == cs2.num_comments()); - REQUIRE(false == cs2.closed()); - REQUIRE(osmium::Timestamp(120) == cs2.created_at()); - REQUIRE(osmium::Timestamp() == cs2.closed_at()); - REQUIRE(2 == cs2.tags().size()); - REQUIRE(std::string("user") == cs2.user()); - - REQUIRE(cs1 != cs2); - - REQUIRE(cs1 < cs2); - REQUIRE(cs1 <= cs2); - REQUIRE(false == (cs1 > cs2)); - REQUIRE(false == (cs1 >= cs2)); - -} - -TEST_CASE("Create changeset without helper") { - osmium::memory::Buffer buffer(10 * 1000); - osmium::builder::ChangesetBuilder builder(buffer); - - osmium::Changeset& cs1 = builder.object(); - cs1.set_id(42) - .set_created_at(100) - .set_closed_at(200) - .set_num_changes(7) - .set_num_comments(2) - .set_uid(9); - - builder.add_user("user"); - add_tags(buffer, builder, { - {"key1", "val1"}, - {"key2", "val2"} - }); - - { - osmium::builder::ChangesetDiscussionBuilder disc_builder(buffer, &builder); - disc_builder.add_comment(osmium::Timestamp(300), 10, "user2"); - disc_builder.add_comment_text("foo"); - disc_builder.add_comment(osmium::Timestamp(400), 9, "user"); - disc_builder.add_comment_text("bar"); - } - - buffer.commit(); - - REQUIRE(42 == cs1.id()); - REQUIRE(9 == cs1.uid()); - REQUIRE(7 == cs1.num_changes()); - REQUIRE(2 == cs1.num_comments()); - REQUIRE(true == cs1.closed()); - REQUIRE(osmium::Timestamp(100) == cs1.created_at()); - REQUIRE(osmium::Timestamp(200) == cs1.closed_at()); - REQUIRE(2 == cs1.tags().size()); - REQUIRE(std::string("user") == cs1.user()); - - auto cit = cs1.discussion().begin(); - - REQUIRE(cit != cs1.discussion().end()); - REQUIRE(cit->date() == osmium::Timestamp(300)); - REQUIRE(cit->uid() == 10); - REQUIRE(std::string("user2") == cit->user()); - REQUIRE(std::string("foo") == cit->text()); - - REQUIRE(++cit != cs1.discussion().end()); - REQUIRE(cit->date() == osmium::Timestamp(400)); - REQUIRE(cit->uid() == 9); - REQUIRE(std::string("user") == cit->user()); - REQUIRE(std::string("bar") == cit->text()); - - REQUIRE(++cit == cs1.discussion().end()); -} - diff --git a/third_party/libosmium/test/t/basic/test_crc.cpp b/third_party/libosmium/test/t/basic/test_crc.cpp deleted file mode 100644 index fcd50a13c..000000000 --- a/third_party/libosmium/test/t/basic/test_crc.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -#include "helper.hpp" - -TEST_CASE("CRC of basic datatypes") { - - osmium::CRC crc32; - - SECTION("Bool") { - crc32.update_bool(true); - crc32.update_bool(false); - - REQUIRE(crc32().checksum() == 0x58c223be); - } - - SECTION("Char") { - crc32.update_int8('x'); - crc32.update_int8('y'); - - REQUIRE(crc32().checksum() == 0x8fe62899); - } - - SECTION("Int16") { - crc32.update_int16(0x0123U); - crc32.update_int16(0x1234U); - - REQUIRE(crc32().checksum() == 0xda923744); - } - - SECTION("Int32") { - crc32.update_int32(0x01234567UL); - crc32.update_int32(0x12345678UL); - - REQUIRE(crc32().checksum() == 0x9b4e2af3); - } - - SECTION("Int64") { - crc32.update_int64(0x0123456789abcdefULL); - crc32.update_int64(0x123456789abcdef0ULL); - - REQUIRE(crc32().checksum() == 0x6d8b7267); - } - - SECTION("String") { - const char* str = "foobar"; - crc32.update_string(str); - - REQUIRE(crc32().checksum() == 0x9ef61f95); - } - - SECTION("Timestamp") { - osmium::Timestamp t("2015-07-12T13:10:46Z"); - crc32.update(t); - - REQUIRE(crc32().checksum() == 0x58a29d7); - } - - SECTION("Location") { - osmium::Location loc { 3.46, 2.001 }; - crc32.update(loc); - - REQUIRE(crc32().checksum() == 0xddee042c); - } - -} - diff --git a/third_party/libosmium/test/t/basic/test_entity_bits.cpp b/third_party/libosmium/test/t/basic/test_entity_bits.cpp deleted file mode 100644 index f15068b1c..000000000 --- a/third_party/libosmium/test/t/basic/test_entity_bits.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("entity_bits") { - - SECTION("can_be_set_and_checked") { - osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way; - REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way)); - - entities |= osmium::osm_entity_bits::relation; - REQUIRE((entities & osmium::osm_entity_bits::object)); - - entities |= osmium::osm_entity_bits::area; - REQUIRE(entities == osmium::osm_entity_bits::object); - - REQUIRE(! (entities & osmium::osm_entity_bits::changeset)); - - entities &= osmium::osm_entity_bits::node; - REQUIRE((entities & osmium::osm_entity_bits::node)); - REQUIRE(! (entities & osmium::osm_entity_bits::way)); - REQUIRE(entities == osmium::osm_entity_bits::node); - - REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node)); - REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way)); - REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation)); - REQUIRE(osmium::osm_entity_bits::changeset == osmium::osm_entity_bits::from_item_type(osmium::item_type::changeset)); - REQUIRE(osmium::osm_entity_bits::area == osmium::osm_entity_bits::from_item_type(osmium::item_type::area)); - } - -} diff --git a/third_party/libosmium/test/t/basic/test_location.cpp b/third_party/libosmium/test/t/basic/test_location.cpp deleted file mode 100644 index 3fd8d155a..000000000 --- a/third_party/libosmium/test/t/basic/test_location.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include - -TEST_CASE("Location") { - -// fails on MSVC and doesn't really matter -// static_assert(std::is_literal_type::value, "osmium::Location not literal type"); - - SECTION("instantiation_with_default_parameters") { - osmium::Location loc; - REQUIRE(!loc); - REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location); - REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location); - } - - SECTION("instantiation_with_double_parameters") { - osmium::Location loc1(1.2, 4.5); - REQUIRE(!!loc1); - REQUIRE(12000000 == loc1.x()); - REQUIRE(45000000 == loc1.y()); - REQUIRE(1.2 == loc1.lon()); - REQUIRE(4.5 == loc1.lat()); - - osmium::Location loc2(loc1); - REQUIRE(4.5 == loc2.lat()); - - osmium::Location loc3 = loc1; - REQUIRE(4.5 == loc3.lat()); - } - - SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") { - osmium::Location loc { 2.2, 3.3 }; - REQUIRE(2.2 == loc.lon()); - REQUIRE(3.3 == loc.lat()); - } - - SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") { - osmium::Location loc({ 4.4, 5.5 }); - REQUIRE(4.4 == loc.lon()); - REQUIRE(5.5 == loc.lat()); - } - - SECTION("instantiation_with_double_parameters_operator_equal") { - osmium::Location loc = { 5.5, 6.6 }; - REQUIRE(5.5 == loc.lon()); - REQUIRE(6.6 == loc.lat()); - } - - SECTION("equality") { - osmium::Location loc1(1.2, 4.5); - osmium::Location loc2(1.2, 4.5); - osmium::Location loc3(1.5, 1.5); - REQUIRE(loc1 == loc2); - REQUIRE(loc1 != loc3); - } - - SECTION("order") { - REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0)); - REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0)); - - REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2)); - REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0)); - REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0)); - } - - SECTION("validity") { - REQUIRE(osmium::Location(0.0, 0.0).valid()); - REQUIRE(osmium::Location(1.2, 4.5).valid()); - REQUIRE(osmium::Location(-1.2, 4.5).valid()); - REQUIRE(osmium::Location(-180.0, -90.0).valid()); - REQUIRE(osmium::Location(180.0, -90.0).valid()); - REQUIRE(osmium::Location(-180.0, 90.0).valid()); - REQUIRE(osmium::Location(180.0, 90.0).valid()); - - REQUIRE(!osmium::Location(200.0, 4.5).valid()); - REQUIRE(!osmium::Location(-1.2, -100.0).valid()); - REQUIRE(!osmium::Location(-180.0, 90.005).valid()); - } - - - SECTION("output_to_iterator_comma_separator") { - char buffer[100]; - osmium::Location loc(-3.2, 47.3); - *loc.as_string(buffer, ',') = 0; - REQUIRE(std::string("-3.2,47.3") == buffer); - } - - SECTION("output_to_iterator_space_separator") { - char buffer[100]; - osmium::Location loc(0.0, 7.0); - *loc.as_string(buffer, ' ') = 0; - REQUIRE(std::string("0 7") == buffer); - } - - SECTION("output_to_iterator_check_precision") { - char buffer[100]; - osmium::Location loc(-179.9999999, -90.0); - *loc.as_string(buffer, ' ') = 0; - REQUIRE(std::string("-179.9999999 -90") == buffer); - } - - SECTION("output_to_iterator_undefined_location") { - char buffer[100]; - osmium::Location loc; - REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location); - } - - SECTION("output_to_string_comman_separator") { - std::string s; - osmium::Location loc(-3.2, 47.3); - loc.as_string(std::back_inserter(s), ','); - REQUIRE(s == "-3.2,47.3"); - } - - SECTION("output_to_string_space_separator") { - std::string s; - osmium::Location loc(0.0, 7.0); - loc.as_string(std::back_inserter(s), ' '); - REQUIRE(s == "0 7"); - } - - SECTION("output_to_string_check_precision") { - std::string s; - osmium::Location loc(-179.9999999, -90.0); - loc.as_string(std::back_inserter(s), ' '); - REQUIRE(s == "-179.9999999 -90"); - } - - SECTION("output_to_string_undefined_location") { - std::string s; - osmium::Location loc; - REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location); - } - - SECTION("output_defined") { - osmium::Location p(-3.2, 47.3); - std::stringstream out; - out << p; - REQUIRE(out.str() == "(-3.2,47.3)"); - } - - SECTION("output_undefined") { - osmium::Location p; - std::stringstream out; - out << p; - REQUIRE(out.str() == "(undefined,undefined)"); - } - -} - diff --git a/third_party/libosmium/test/t/basic/test_node.cpp b/third_party/libosmium/test/t/basic/test_node.cpp deleted file mode 100644 index 9f8b181fe..000000000 --- a/third_party/libosmium/test/t/basic/test_node.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include - -#include "helper.hpp" - -TEST_CASE("Basic_Node") { - - osmium::CRC crc32; - -SECTION("node_builder") { - osmium::memory::Buffer buffer(10000); - - osmium::Node& node = buffer_add_node(buffer, - "foo", - {{"amenity", "pub"}, {"name", "OSM BAR"}}, - {3.5, 4.7}); - - node.set_id(17) - .set_version(3) - .set_visible(true) - .set_changeset(333) - .set_uid(21) - .set_timestamp(123); - - REQUIRE(osmium::item_type::node == node.type()); - REQUIRE(node.type_is_in(osmium::osm_entity_bits::node)); - REQUIRE(node.type_is_in(osmium::osm_entity_bits::nwr)); - REQUIRE(17l == node.id()); - REQUIRE(17ul == node.positive_id()); - REQUIRE(3 == node.version()); - REQUIRE(true == node.visible()); - REQUIRE(false == node.deleted()); - REQUIRE(333 == node.changeset()); - REQUIRE(21 == node.uid()); - REQUIRE(std::string("foo") == node.user()); - REQUIRE(123 == uint32_t(node.timestamp())); - REQUIRE(osmium::Location(3.5, 4.7) == node.location()); - REQUIRE(2 == node.tags().size()); - - crc32.update(node); - REQUIRE(crc32().checksum() == 0x7dc553f9); - - node.set_visible(false); - REQUIRE(false == node.visible()); - REQUIRE(true == node.deleted()); -} - -SECTION("node_default_attributes") { - osmium::memory::Buffer buffer(10000); - - osmium::Node& node = buffer_add_node(buffer, "", {}, osmium::Location{}); - - REQUIRE(0l == node.id()); - REQUIRE(0ul == node.positive_id()); - REQUIRE(0 == node.version()); - REQUIRE(true == node.visible()); - REQUIRE(0 == node.changeset()); - REQUIRE(0 == node.uid()); - REQUIRE(std::string("") == node.user()); - REQUIRE(0 == uint32_t(node.timestamp())); - REQUIRE(osmium::Location() == node.location()); - REQUIRE(0 == node.tags().size()); -} - -SECTION("set_node_attributes_from_string") { - osmium::memory::Buffer buffer(10000); - - osmium::Node& node = buffer_add_node(buffer, - "foo", - {{"amenity", "pub"}, {"name", "OSM BAR"}}, - {3.5, 4.7}); - - node.set_id("-17") - .set_version("3") - .set_visible(true) - .set_changeset("333") - .set_uid("21"); - - REQUIRE(-17l == node.id()); - REQUIRE(17ul == node.positive_id()); - REQUIRE(3 == node.version()); - REQUIRE(true == node.visible()); - REQUIRE(333 == node.changeset()); - REQUIRE(21 == node.uid()); -} - -SECTION("large_id") { - osmium::memory::Buffer buffer(10000); - - osmium::Node& node = buffer_add_node(buffer, "", {}, osmium::Location{}); - - int64_t id = 3000000000l; - node.set_id(id); - - REQUIRE(id == node.id()); - REQUIRE(static_cast(id) == node.positive_id()); - - node.set_id(-id); - REQUIRE(-id == node.id()); - REQUIRE(static_cast(id) == node.positive_id()); -} - -SECTION("tags") { - osmium::memory::Buffer buffer(10000); - - osmium::Node& node = buffer_add_node(buffer, - "foo", - {{"amenity", "pub"}, {"name", "OSM BAR"}}, - {3.5, 4.7}); - - REQUIRE(nullptr == node.tags().get_value_by_key("fail")); - REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity")); - REQUIRE(std::string("pub") == node.get_value_by_key("amenity")); - - REQUIRE(std::string("default") == node.tags().get_value_by_key("fail", "default")); - REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity", "default")); - REQUIRE(std::string("pub") == node.get_value_by_key("amenity", "default")); -} - - -} diff --git a/third_party/libosmium/test/t/basic/test_node_ref.cpp b/third_party/libosmium/test/t/basic/test_node_ref.cpp deleted file mode 100644 index ac7ccbf4b..000000000 --- a/third_party/libosmium/test/t/basic/test_node_ref.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("NodeRef") { - - SECTION("instantiation_with_default_parameters") { - osmium::NodeRef node_ref; - REQUIRE(node_ref.ref() == 0); -// REQUIRE(!node_ref.has_location()); - } - - SECTION("instantiation_with_id") { - osmium::NodeRef node_ref(7); - REQUIRE(node_ref.ref() == 7); - } - - SECTION("equality") { - osmium::NodeRef node_ref1(7, { 1.2, 3.4 }); - osmium::NodeRef node_ref2(7, { 1.4, 3.1 }); - osmium::NodeRef node_ref3(9, { 1.2, 3.4 }); - REQUIRE(node_ref1 == node_ref2); - REQUIRE(node_ref1 != node_ref3); - REQUIRE(!osmium::location_equal()(node_ref1, node_ref2)); - REQUIRE(!osmium::location_equal()(node_ref2, node_ref3)); - REQUIRE(osmium::location_equal()(node_ref1, node_ref3)); - } - - SECTION("set_location") { - osmium::NodeRef node_ref(7); - REQUIRE(!node_ref.location().valid()); - REQUIRE(node_ref.location() == osmium::Location()); - node_ref.set_location(osmium::Location(13.5, -7.2)); - REQUIRE(node_ref.location().lon() == 13.5); - REQUIRE(node_ref.location().valid()); - } - - SECTION("ordering") { - osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); - osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); - osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); - osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); - - REQUIRE(node_ref1 < node_ref2); - REQUIRE(node_ref2 < node_ref3); - REQUIRE(node_ref1 < node_ref3); - REQUIRE(node_ref1 >= node_ref1); - - REQUIRE(osmium::location_less()(node_ref1, node_ref2)); - REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); - REQUIRE(osmium::location_less()(node_ref1, node_ref3)); - REQUIRE(osmium::location_less()(node_ref3, node_ref4)); - REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); - } - -} - diff --git a/third_party/libosmium/test/t/basic/test_object_comparisons.cpp b/third_party/libosmium/test/t/basic/test_object_comparisons.cpp deleted file mode 100644 index ec9e6fae8..000000000 --- a/third_party/libosmium/test/t/basic/test_object_comparisons.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "catch.hpp" - -#include -#include -#include - -TEST_CASE("Object_Comparisons") { - - SECTION("order") { - osmium::memory::Buffer buffer(10 * 1000); - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - buffer.commit(); - } - - { - // add node 2 - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - buffer.commit(); - } - - auto it = buffer.begin(); - osmium::Node& node1 = static_cast(*it); - osmium::Node& node2 = static_cast(*(++it)); - - node1.set_id(10); - node1.set_version(1); - node2.set_id(15); - node2.set_version(2); - REQUIRE(node1 < node2); - REQUIRE_FALSE(node1 > node2); - node1.set_id(20); - node1.set_version(1); - node2.set_id(20); - node2.set_version(2); - REQUIRE(node1 < node2); - REQUIRE_FALSE(node1 > node2); - node1.set_id(-10); - node1.set_version(2); - node2.set_id(-15); - node2.set_version(1); - REQUIRE(node1 < node2); - REQUIRE_FALSE(node1 > node2); - } - - SECTION("order_types") { - osmium::memory::Buffer buffer(10 * 1000); - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(3); - node.set_version(3); - node_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add node 2 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(3); - node.set_version(4); - node_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add node 3 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(3); - node.set_version(4); - node_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add way - osmium::builder::WayBuilder way_builder(buffer); - osmium::Way& way = way_builder.object(); - REQUIRE(osmium::item_type::way == way.type()); - - way.set_id(2); - way.set_version(2); - way_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add relation - osmium::builder::RelationBuilder relation_builder(buffer); - osmium::Relation& relation = relation_builder.object(); - REQUIRE(osmium::item_type::relation == relation.type()); - - relation.set_id(1); - relation.set_version(1); - relation_builder.add_user("testuser"); - - buffer.commit(); - } - - auto it = buffer.begin(); - const osmium::Node& node1 = static_cast(*it); - const osmium::Node& node2 = static_cast(*(++it)); - const osmium::Node& node3 = static_cast(*(++it)); - const osmium::Way& way = static_cast(*(++it)); - const osmium::Relation& relation = static_cast(*(++it)); - - REQUIRE(node1 < node2); - REQUIRE(node2 < way); - REQUIRE_FALSE(node2 > way); - REQUIRE(way < relation); - REQUIRE(node1 < relation); - - REQUIRE(osmium::object_order_type_id_version()(node1, node2)); - REQUIRE(osmium::object_order_type_id_reverse_version()(node2, node1)); - REQUIRE(osmium::object_order_type_id_version()(node1, way)); - REQUIRE(osmium::object_order_type_id_reverse_version()(node1, way)); - - REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, node2)); - REQUIRE(osmium::object_equal_type_id_version()(node2, node3)); - - REQUIRE(osmium::object_equal_type_id()(node1, node2)); - REQUIRE(osmium::object_equal_type_id()(node2, node3)); - - REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, way)); - REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, relation)); - REQUIRE_FALSE(osmium::object_equal_type_id()(node1, relation)); - } - -} diff --git a/third_party/libosmium/test/t/basic/test_relation.cpp b/third_party/libosmium/test/t/basic/test_relation.cpp deleted file mode 100644 index 66b201c90..000000000 --- a/third_party/libosmium/test/t/basic/test_relation.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include - -#include "helper.hpp" - -TEST_CASE("Build relation") { - - osmium::CRC crc32; - - osmium::memory::Buffer buffer(10000); - - osmium::Relation& relation = buffer_add_relation(buffer, - "foo", { - {"type", "multipolygon"}, - {"name", "Sherwood Forest"} - }, { - std::make_tuple('w', 1, "inner"), - std::make_tuple('w', 2, ""), - std::make_tuple('w', 3, "outer") - }); - - relation.set_id(17) - .set_version(3) - .set_visible(true) - .set_changeset(333) - .set_uid(21) - .set_timestamp(123); - - REQUIRE(17 == relation.id()); - REQUIRE(3 == relation.version()); - REQUIRE(true == relation.visible()); - REQUIRE(333 == relation.changeset()); - REQUIRE(21 == relation.uid()); - REQUIRE(std::string("foo") == relation.user()); - REQUIRE(123 == uint32_t(relation.timestamp())); - REQUIRE(2 == relation.tags().size()); - REQUIRE(3 == relation.members().size()); - - int n=1; - for (auto& member : relation.members()) { - REQUIRE(osmium::item_type::way == member.type()); - REQUIRE(n == member.ref()); - switch (n) { - case 1: - REQUIRE(std::string("inner") == member.role()); - break; - case 2: - REQUIRE(std::string("") == member.role()); - break; - case 3: - REQUIRE(std::string("outer") == member.role()); - break; - default: - REQUIRE(false); - } - ++n; - } - - crc32.update(relation); - REQUIRE(crc32().checksum() == 0x2c2352e); -} - -TEST_CASE("Member role too long") { - osmium::memory::Buffer buffer(10000); - - osmium::builder::RelationMemberListBuilder builder(buffer); - - const char role[2000] = ""; - builder.add_member(osmium::item_type::node, 1, role, 1024); - REQUIRE_THROWS(builder.add_member(osmium::item_type::node, 1, role, 1025)); -} - diff --git a/third_party/libosmium/test/t/basic/test_timestamp.cpp b/third_party/libosmium/test/t/basic/test_timestamp.cpp deleted file mode 100644 index f80ffcf5f..000000000 --- a/third_party/libosmium/test/t/basic/test_timestamp.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -TEST_CASE("Timestamp") { - - SECTION("can be default initialized to invalid value") { - osmium::Timestamp t; - REQUIRE(0 == uint32_t(t)); - REQUIRE("" == t.to_iso()); - REQUIRE_FALSE(t.valid()); - } - - SECTION("invalid value is zero") { - osmium::Timestamp t(static_cast(0)); - REQUIRE(0 == uint32_t(t)); - REQUIRE("" == t.to_iso()); - REQUIRE_FALSE(t.valid()); - } - - SECTION("can be initialized from time_t") { - osmium::Timestamp t(static_cast(1)); - REQUIRE(1 == uint32_t(t)); - REQUIRE("1970-01-01T00:00:01Z" == t.to_iso()); - REQUIRE(t.valid()); - } - - SECTION("can be initialized from const char*") { - osmium::Timestamp t("2000-01-01T00:00:00Z"); - REQUIRE("2000-01-01T00:00:00Z" == t.to_iso()); - REQUIRE(t.valid()); - } - - SECTION("can be initialized from string") { - std::string s = "2000-01-01T00:00:00Z"; - osmium::Timestamp t(s); - REQUIRE("2000-01-01T00:00:00Z" == t.to_iso()); - REQUIRE(t.valid()); - } - - SECTION("throws if initialized from bad string") { - REQUIRE_THROWS_AS(osmium::Timestamp("x"), std::invalid_argument); - } - - SECTION("can be explicitly cast to time_t") { - osmium::Timestamp t(4242); - time_t x = t.seconds_since_epoch(); - REQUIRE(x == 4242); - } - - SECTION("uint32_t can be initialized from Timestamp") { - osmium::Timestamp t(4242); - uint32_t x { t }; - - REQUIRE(x == 4242); - } - - SECTION("can be compared") { - osmium::Timestamp t1(10); - osmium::Timestamp t2(50); - REQUIRE(t1 < t2); - REQUIRE(t1 > osmium::start_of_time()); - REQUIRE(t2 > osmium::start_of_time()); - REQUIRE(t1 < osmium::end_of_time()); - REQUIRE(t2 < osmium::end_of_time()); - } - - SECTION("can be written to stream") { - std::stringstream ss; - osmium::Timestamp t(1); - ss << t; - REQUIRE("1970-01-01T00:00:01Z" == ss.str()); - } - -} diff --git a/third_party/libosmium/test/t/basic/test_types_from_string.cpp b/third_party/libosmium/test/t/basic/test_types_from_string.cpp deleted file mode 100644 index 2481ae876..000000000 --- a/third_party/libosmium/test/t/basic/test_types_from_string.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "catch.hpp" - -#include -#include - -TEST_CASE("set ID from string") { - REQUIRE(osmium::string_to_object_id("0") == 0); - REQUIRE(osmium::string_to_object_id("17") == 17); - REQUIRE(osmium::string_to_object_id("-17") == -17); - REQUIRE(osmium::string_to_object_id("01") == 1); - - REQUIRE_THROWS_AS(osmium::string_to_object_id(""), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id(" "), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id(" 22"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("x"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("0x1"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("12a"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("12345678901234567890"), std::range_error); -} - -TEST_CASE("set type and ID from string") { - auto n17 = osmium::string_to_object_id("n17", osmium::osm_entity_bits::nwr); - REQUIRE(n17.first == osmium::item_type::node); - REQUIRE(n17.second == 17); - - auto w42 = osmium::string_to_object_id("w42", osmium::osm_entity_bits::nwr); - REQUIRE(w42.first == osmium::item_type::way); - REQUIRE(w42.second == 42); - - auto r_2 = osmium::string_to_object_id("r-2", osmium::osm_entity_bits::nwr); - REQUIRE(r_2.first == osmium::item_type::relation); - REQUIRE(r_2.second == -2); - - auto x3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr); - REQUIRE(x3.first == osmium::item_type::undefined); - REQUIRE(x3.second == 3); - - REQUIRE_THROWS_AS(osmium::string_to_object_id("", osmium::osm_entity_bits::nwr), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("n", osmium::osm_entity_bits::nwr), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("x3", osmium::osm_entity_bits::nwr), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("nx3", osmium::osm_entity_bits::nwr), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("n3", osmium::osm_entity_bits::way), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_id("n3a", osmium::osm_entity_bits::nwr), std::range_error); -} - -TEST_CASE("set object version from string") { - REQUIRE(osmium::string_to_object_version("0") == 0); - REQUIRE(osmium::string_to_object_version("1") == 1); - - REQUIRE_THROWS_AS(osmium::string_to_object_version("-1"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_version(""), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_version(" "), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_version(" 22"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_object_version("x"), std::range_error); -} - -TEST_CASE("set changeset id from string") { - REQUIRE(osmium::string_to_changeset_id("0") == 0); - REQUIRE(osmium::string_to_changeset_id("1") == 1); - - REQUIRE_THROWS_AS(osmium::string_to_changeset_id("-1"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_changeset_id(""), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_changeset_id(" "), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_changeset_id(" 22"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_changeset_id("x"), std::range_error); -} - -TEST_CASE("set user id from string") { - REQUIRE(osmium::string_to_user_id("0") == 0); - REQUIRE(osmium::string_to_user_id("1") == 1); - REQUIRE(osmium::string_to_user_id("-1") == -1); - - REQUIRE_THROWS_AS(osmium::string_to_user_id("-2"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_user_id(""), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_user_id(" "), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_user_id(" 22"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_user_id("x"), std::range_error); -} - -TEST_CASE("set num changes from string") { - REQUIRE(osmium::string_to_num_changes("0") == 0); - REQUIRE(osmium::string_to_num_changes("1") == 1); - - REQUIRE_THROWS_AS(osmium::string_to_num_changes("-1"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_num_changes(""), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_num_changes(" "), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_num_changes(" 22"), std::range_error); - REQUIRE_THROWS_AS(osmium::string_to_num_changes("x"), std::range_error); -} - diff --git a/third_party/libosmium/test/t/basic/test_way.cpp b/third_party/libosmium/test/t/basic/test_way.cpp deleted file mode 100644 index 370cd0105..000000000 --- a/third_party/libosmium/test/t/basic/test_way.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include -#include - -#include "helper.hpp" - -TEST_CASE("Build way") { - - osmium::CRC crc32; - -SECTION("way_builder") { - osmium::memory::Buffer buffer(10000); - - osmium::Way& way = buffer_add_way(buffer, - "foo", - {{"highway", "residential"}, {"name", "High Street"}}, - {1, 3, 2}); - - way.set_id(17) - .set_version(3) - .set_visible(true) - .set_changeset(333) - .set_uid(21) - .set_timestamp(123); - - REQUIRE(osmium::item_type::way == way.type()); - REQUIRE(way.type_is_in(osmium::osm_entity_bits::way)); - REQUIRE(way.type_is_in(osmium::osm_entity_bits::node | osmium::osm_entity_bits::way)); - REQUIRE(17 == way.id()); - REQUIRE(3 == way.version()); - REQUIRE(true == way.visible()); - REQUIRE(333 == way.changeset()); - REQUIRE(21 == way.uid()); - REQUIRE(std::string("foo") == way.user()); - REQUIRE(123 == uint32_t(way.timestamp())); - REQUIRE(2 == way.tags().size()); - REQUIRE(3 == way.nodes().size()); - REQUIRE(1 == way.nodes()[0].ref()); - REQUIRE(3 == way.nodes()[1].ref()); - REQUIRE(2 == way.nodes()[2].ref()); - REQUIRE(! way.is_closed()); - - crc32.update(way); - REQUIRE(crc32().checksum() == 0x7676d0c2); -} - -SECTION("closed_way") { - osmium::memory::Buffer buffer(10000); - - osmium::Way& way = buffer_add_way(buffer, - "foo", - {{"highway", "residential"}, {"name", "High Street"}}, - {1, 3, 1}); - - REQUIRE(way.is_closed()); -} - -SECTION("way_builder_with_helpers") { - osmium::memory::Buffer buffer(10000); - { - osmium::builder::WayBuilder builder(buffer); - builder.add_user("username"); - builder.add_tags({ - {"amenity", "restaurant"}, - {"name", "Zum goldenen Schwanen"} - }); - builder.add_node_refs({ - {22, {3.5, 4.7}}, - {67, {4.1, 2.2}} - }); - } - buffer.commit(); - osmium::Way& way = buffer.get(0); - - REQUIRE(std::string("username") == way.user()); - - REQUIRE(2 == way.tags().size()); - REQUIRE(std::string("amenity") == way.tags().begin()->key()); - REQUIRE(std::string("Zum goldenen Schwanen") == way.tags()["name"]); - - REQUIRE(2 == way.nodes().size()); - REQUIRE(22 == way.nodes()[0].ref()); - REQUIRE(4.1 == way.nodes()[1].location().lon()); -} - -} diff --git a/third_party/libosmium/test/t/buffer/test_buffer_basics.cpp b/third_party/libosmium/test/t/buffer/test_buffer_basics.cpp deleted file mode 100644 index ffe725168..000000000 --- a/third_party/libosmium/test/t/buffer/test_buffer_basics.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("Buffer basics") { - - osmium::memory::Buffer invalid_buffer1; - osmium::memory::Buffer invalid_buffer2; - osmium::memory::Buffer empty_buffer1(1024); - osmium::memory::Buffer empty_buffer2(2048); - - REQUIRE(!invalid_buffer1); - REQUIRE(!invalid_buffer2); - REQUIRE(empty_buffer1); - REQUIRE(empty_buffer2); - - REQUIRE(invalid_buffer1 == invalid_buffer2); - REQUIRE(invalid_buffer1 != empty_buffer1); - REQUIRE(empty_buffer1 != empty_buffer2); - - REQUIRE(invalid_buffer1.capacity() == 0); - REQUIRE(invalid_buffer1.written() == 0); - REQUIRE(invalid_buffer1.committed() == 0); - - REQUIRE(empty_buffer1.capacity() == 1024); - REQUIRE(empty_buffer1.written() == 0); - REQUIRE(empty_buffer1.committed() == 0); - - REQUIRE(empty_buffer2.capacity() == 2048); - REQUIRE(empty_buffer2.written() == 0); - REQUIRE(empty_buffer2.committed() == 0); - -} - diff --git a/third_party/libosmium/test/t/buffer/test_buffer_node.cpp b/third_party/libosmium/test/t/buffer/test_buffer_node.cpp deleted file mode 100644 index ba2431b80..000000000 --- a/third_party/libosmium/test/t/buffer/test_buffer_node.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include "catch.hpp" - -#include -#include - -void check_node_1(osmium::Node& node) { - REQUIRE(1 == node.id()); - REQUIRE(3 == node.version()); - REQUIRE(true == node.visible()); - REQUIRE(333 == node.changeset()); - REQUIRE(21 == node.uid()); - REQUIRE(123 == uint32_t(node.timestamp())); - REQUIRE(osmium::Location(3.5, 4.7) == node.location()); - REQUIRE(std::string("testuser") == node.user()); - - for (osmium::memory::Item& item : node) { - REQUIRE(osmium::item_type::tag_list == item.type()); - } - - REQUIRE(node.tags().begin() == node.tags().end()); - REQUIRE(node.tags().empty()); - REQUIRE(0 == std::distance(node.tags().begin(), node.tags().end())); -} - -void check_node_2(osmium::Node& node) { - REQUIRE(2 == node.id()); - REQUIRE(3 == node.version()); - REQUIRE(true == node.visible()); - REQUIRE(333 == node.changeset()); - REQUIRE(21 == node.uid()); - REQUIRE(123 == uint32_t(node.timestamp())); - REQUIRE(osmium::Location(3.5, 4.7) == node.location()); - REQUIRE(std::string("testuser") == node.user()); - - for (osmium::memory::Item& item : node) { - REQUIRE(osmium::item_type::tag_list == item.type()); - } - - REQUIRE(!node.tags().empty()); - REQUIRE(2 == std::distance(node.tags().begin(), node.tags().end())); - - int n = 0; - for (const osmium::Tag& tag : node.tags()) { - switch (n) { - case 0: - REQUIRE(std::string("amenity") == tag.key()); - REQUIRE(std::string("bank") == tag.value()); - break; - case 1: - REQUIRE(std::string("name") == tag.key()); - REQUIRE(std::string("OSM Savings") == tag.value()); - break; - } - ++n; - } - REQUIRE(2 == n); -} - -TEST_CASE("Node in Buffer") { - - constexpr size_t buffer_size = 10000; - unsigned char data[buffer_size]; - - osmium::memory::Buffer buffer(data, buffer_size, 0); - - SECTION("Add node to buffer") { - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(1); - node.set_version(3); - node.set_visible(true); - node.set_changeset(333); - node.set_uid(21); - node.set_timestamp(123); - node.set_location(osmium::Location(3.5, 4.7)); - - node_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add node 2 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(2); - node.set_version(3); - node.set_visible(true); - node.set_changeset(333); - node.set_uid(21); - node.set_timestamp(123); - node.set_location(osmium::Location(3.5, 4.7)); - - node_builder.add_user("testuser"); - - { - osmium::builder::TagListBuilder tag_builder(buffer, &node_builder); - tag_builder.add_tag("amenity", "bank"); - tag_builder.add_tag("name", "OSM Savings"); - } - - buffer.commit(); - } - - REQUIRE(2 == std::distance(buffer.begin(), buffer.end())); - int item_no = 0; - for (osmium::memory::Item& item : buffer) { - REQUIRE(osmium::item_type::node == item.type()); - - osmium::Node& node = static_cast(item); - - switch (item_no) { - case 0: - check_node_1(node); - break; - case 1: - check_node_2(node); - break; - default: - break; - } - - ++item_no; - - } - - } - - SECTION("Add buffer to another one") { - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(1); - node.set_version(3); - node.set_visible(true); - node.set_changeset(333); - node.set_uid(21); - node.set_timestamp(123); - node.set_location(osmium::Location(3.5, 4.7)); - - node_builder.add_user("testuser"); - - buffer.commit(); - } - - osmium::memory::Buffer buffer2(buffer_size, osmium::memory::Buffer::auto_grow::yes); - - buffer2.add_buffer(buffer); - buffer2.commit(); - - REQUIRE(buffer.committed() == buffer2.committed()); - const osmium::Node& node = buffer2.get(0); - REQUIRE(node.id() == 1); - REQUIRE(123 == uint32_t(node.timestamp())); - } - - SECTION("Use back_inserter on buffer") { - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(1); - node.set_version(3); - node.set_visible(true); - node.set_changeset(333); - node.set_uid(21); - node.set_timestamp(123); - node.set_location(osmium::Location(3.5, 4.7)); - - node_builder.add_user("testuser"); - - buffer.commit(); - } - - osmium::memory::Buffer buffer2(buffer_size, osmium::memory::Buffer::auto_grow::yes); - - std::copy(buffer.begin(), buffer.end(), std::back_inserter(buffer2)); - - REQUIRE(buffer.committed() == buffer2.committed()); - const osmium::Node& node = buffer2.get(0); - REQUIRE(node.id() == 1); - REQUIRE(123 == uint32_t(node.timestamp())); - } -} - diff --git a/third_party/libosmium/test/t/buffer/test_buffer_purge.cpp b/third_party/libosmium/test/t/buffer/test_buffer_purge.cpp deleted file mode 100644 index a72db1b5c..000000000 --- a/third_party/libosmium/test/t/buffer/test_buffer_purge.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include "catch.hpp" - -#include -#include - -struct CallbackClass { - - int count = 0; - - void moving_in_buffer(size_t old_offset, size_t new_offset) { - REQUIRE(old_offset > new_offset); - ++count; - } - -}; // struct CallbackClass - -TEST_CASE("Purge data from buffer") { - - constexpr size_t buffer_size = 10000; - - SECTION("purge empty buffer") { - osmium::memory::Buffer buffer(buffer_size); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 0); - REQUIRE(buffer.committed() == 0); - } - - SECTION("purge buffer with one object but nothing to delete") { - osmium::memory::Buffer buffer(buffer_size); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - } - buffer.commit(); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1); - size_t committed = buffer.committed(); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 0); - REQUIRE(committed == buffer.committed()); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1); - } - - SECTION("purge buffer with one object which gets deleted") { - osmium::memory::Buffer buffer(buffer_size); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - node_builder.object().set_removed(true); - } - buffer.commit(); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 0); - REQUIRE(buffer.committed() == 0); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0); - } - - SECTION("purge buffer with two objects, first gets deleted") { - osmium::memory::Buffer buffer(buffer_size); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - node_builder.object().set_removed(true); - } - buffer.commit(); - size_t size1 = buffer.committed(); - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - } - buffer.commit(); - size_t size2 = buffer.committed() - size1; - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 1); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1); - REQUIRE(buffer.committed() == size2); - } - - SECTION("purge buffer with two objects, second gets deleted") { - osmium::memory::Buffer buffer(buffer_size); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser_longer_name"); - } - buffer.commit(); - size_t size1 = buffer.committed(); - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - node_builder.object().set_removed(true); - } - buffer.commit(); - - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 0); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1); - REQUIRE(buffer.committed() == size1); - } - - SECTION("purge buffer with three objects, middle one gets deleted") { - osmium::memory::Buffer buffer(buffer_size); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser_longer_name"); - } - buffer.commit(); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - node_builder.object().set_removed(true); - } - buffer.commit(); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("sn"); - } - buffer.commit(); - - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 1); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2); - } - - SECTION("purge buffer with three objects, all get deleted") { - osmium::memory::Buffer buffer(buffer_size); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser_longer_name"); - node_builder.object().set_removed(true); - } - buffer.commit(); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - node_builder.object().set_removed(true); - } - buffer.commit(); - - { - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("sn"); - node_builder.object().set_removed(true); - } - buffer.commit(); - - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3); - - CallbackClass callback; - buffer.purge_removed(&callback); - - REQUIRE(callback.count == 0); - REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0); - } - -} diff --git a/third_party/libosmium/test/t/geom/helper.hpp b/third_party/libosmium/test/t/geom/helper.hpp deleted file mode 100644 index e0cefe6d1..000000000 --- a/third_party/libosmium/test/t/geom/helper.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef TEST_GEOM_HELPER_HPP -#define TEST_GEOM_HELPER_HPP - -#include - -#include - -inline std::string geos_to_wkb(const geos::geom::Geometry* geometry) { - std::stringstream ss; - geos::io::WKBWriter wkb_writer; - wkb_writer.writeHEX(*geometry, ss); - return ss.str(); -} - -#endif // TEST_GEOM_HELPER_HPP diff --git a/third_party/libosmium/test/t/geom/test_exception.cpp b/third_party/libosmium/test/t/geom/test_exception.cpp deleted file mode 100644 index fe950434b..000000000 --- a/third_party/libosmium/test/t/geom/test_exception.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -TEST_CASE("Geometry exception") { - - SECTION("geometry_error") { - osmium::geometry_error e("some error message", "node", 17); - REQUIRE(e.id() == 17); - REQUIRE(std::string(e.what()) == "some error message (node_id=17)"); - } - -} - diff --git a/third_party/libosmium/test/t/geom/test_factory_with_projection.cpp b/third_party/libosmium/test/t/geom/test_factory_with_projection.cpp deleted file mode 100644 index 42fc864bb..000000000 --- a/third_party/libosmium/test/t/geom/test_factory_with_projection.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "catch.hpp" - -#include -#include -#include -#include -#include - -#include "helper.hpp" - -TEST_CASE("Projection") { - - SECTION("point_mercator") { - osmium::geom::WKTFactory factory(2); - - std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string {"POINT(356222.37 467961.14)"} == wkt); - } - - SECTION("point_epsg_3857") { - osmium::geom::WKTFactory factory(osmium::geom::Projection(3857), 2); - - std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string {"POINT(356222.37 467961.14)"} == wkt); - } - - SECTION("wkb_with_parameter") { - osmium::geom::WKBFactory wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory geos_factory(osmium::geom::Projection(3857)); - - std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2)); - std::unique_ptr geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2)); - REQUIRE(geos_to_wkb(geos_point.get()) == wkb); - } - - SECTION("cleanup") { - // trying to make valgrind happy, but there is still a memory leak in proj library - pj_deallocate_grids(); - } - -} diff --git a/third_party/libosmium/test/t/geom/test_geojson.cpp b/third_party/libosmium/test/t/geom/test_geojson.cpp deleted file mode 100644 index 8d7df3521..000000000 --- a/third_party/libosmium/test/t/geom/test_geojson.cpp +++ /dev/null @@ -1,236 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include "../basic/helper.hpp" - -TEST_CASE("GeoJSON_Geometry") { - -SECTION("point") { - osmium::geom::GeoJSONFactory<> factory; - - std::string json {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json); -} - -SECTION("empty_point") { - osmium::geom::GeoJSONFactory<> factory; - - REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location); -} - -SECTION("linestring") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - { - std::string json {factory.create_linestring(wnl)}; - REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.2,4.2],[3.5,4.7],[3.6,4.9]]}"} == json); - } - - { - std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)}; - REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.6,4.9],[3.5,4.7],[3.2,4.2]]}"} == json); - } - - { - std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.2,4.2],[3.5,4.7],[3.5,4.7],[3.6,4.9]]}"} == json); - } - - { - std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.6,4.9],[3.5,4.7],[3.5,4.7],[3.2,4.2]]}"} == json); - } -} - -SECTION("empty_linestring") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, {}); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error); -} - -SECTION("linestring_with_two_same_locations") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.5, 4.7}}, - {2, {3.5, 4.7}} - }); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error); - - { - std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json); - } - - { - std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json); - } -} - -SECTION("linestring_with_undefined_location") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.5, 4.7}}, - {2, osmium::Location()} - }); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location); -} - -SECTION("area_1outer_0inner") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {3.2, 4.2}}, - {2, {3.5, 4.7}}, - {3, {3.6, 4.9}}, - {1, {3.2, 4.2}} - }} - }); - - REQUIRE(!area.is_multipolygon()); - REQUIRE(std::distance(area.cbegin(), area.cend()) == 2); - REQUIRE(std::distance(area.cbegin(), area.cend()) == area.num_rings().first); - - { - std::string json {factory.create_multipolygon(area)}; - REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[3.2,4.2],[3.5,4.7],[3.6,4.9],[3.2,4.2]]]]}"} == json); - } -} - -SECTION("area_1outer_1inner") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {8.0, 1.0}}, - {7, {8.0, 8.0}}, - {8, {1.0, 8.0}}, - {5, {1.0, 1.0}} - }} - }); - - REQUIRE(!area.is_multipolygon()); - REQUIRE(std::distance(area.cbegin(), area.cend()) == 3); - REQUIRE(std::distance(area.cbegin(), area.cend()) == area.num_rings().first); - REQUIRE(std::distance(area.cbegin(), area.cend()) == area.num_rings().second); - - { - std::string json {factory.create_multipolygon(area)}; - REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.1,0.1],[9.1,0.1],[9.1,9.1],[0.1,9.1],[0.1,0.1]],[[1,1],[8,1],[8,8],[1,8],[1,1]]]]}"} == json); - } -} - -SECTION("area_2outer_2inner") { - osmium::geom::GeoJSONFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {4.0, 1.0}}, - {7, {4.0, 4.0}}, - {8, {1.0, 4.0}}, - {5, {1.0, 1.0}} - }}, - { false, { - {10, {5.0, 5.0}}, - {11, {5.0, 7.0}}, - {12, {7.0, 7.0}}, - {10, {5.0, 5.0}} - }}, - { true, { - {100, {10.0, 10.0}}, - {101, {11.0, 10.0}}, - {102, {11.0, 11.0}}, - {103, {10.0, 11.0}}, - {100, {10.0, 10.0}} - }} - }); - - REQUIRE(area.is_multipolygon()); - REQUIRE(std::distance(area.cbegin(), area.cend()) == 5); - REQUIRE(std::distance(area.cbegin(), area.cend()) == area.num_rings().first); - REQUIRE(std::distance(area.cbegin(), area.cend()) == area.num_rings().second); - - int outer_ring=0; - int inner_ring=0; - for (auto it_outer = area.cbegin(); it_outer != area.cend(); ++it_outer) { - if (outer_ring == 0) { - REQUIRE(it_outer->front().ref() == 1); - } else if (outer_ring == 1) { - REQUIRE(it_outer->front().ref() == 100); - } else { - REQUIRE(false); - } - for (auto it_inner = area.inner_ring_cbegin(it_outer); it_inner != area.inner_ring_cend(it_outer); ++it_inner) { - if (outer_ring == 0 && inner_ring == 0) { - REQUIRE(it_inner->front().ref() == 5); - } else if (outer_ring == 0 && inner_ring == 1) { - REQUIRE(it_inner->front().ref() == 10); - } else { - REQUIRE(false); - } - ++inner_ring; - } - inner_ring = 0; - ++outer_ring; - } - - { - std::string json {factory.create_multipolygon(area)}; - REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.1,0.1],[9.1,0.1],[9.1,9.1],[0.1,9.1],[0.1,0.1]],[[1,1],[4,1],[4,4],[1,4],[1,1]],[[5,5],[5,7],[7,7],[5,5]]],[[[10,10],[11,10],[11,11],[10,11],[10,10]]]]}"} == json); - } -} - -} - diff --git a/third_party/libosmium/test/t/geom/test_geos.cpp b/third_party/libosmium/test/t/geom/test_geos.cpp deleted file mode 100644 index d849e3b16..000000000 --- a/third_party/libosmium/test/t/geom/test_geos.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include "../basic/helper.hpp" - -TEST_CASE("GEOS geometry factory - create point") { - osmium::geom::GEOSFactory<> factory; - - std::unique_ptr point {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(3.2 == point->getX()); - REQUIRE(4.2 == point->getY()); - REQUIRE(-1 == point->getSRID()); -} - -TEST_CASE("GEOS geometry factory - create point with non-default srid") { - osmium::geom::GEOSFactory<> factory(4326); - - std::unique_ptr point {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(3.2 == point->getX()); - REQUIRE(4.2 == point->getY()); - REQUIRE(4326 == point->getSRID()); -} - -TEST_CASE("GEOS geometry factory - create point with externally created GEOS factory") { - geos::geom::GeometryFactory geos_factory; - osmium::geom::GEOSFactory<> factory(geos_factory); - - std::unique_ptr point {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(3.2 == point->getX()); - REQUIRE(4.2 == point->getY()); - REQUIRE(0 == point->getSRID()); -} - -TEST_CASE("GEOS geometry factory - can not create from invalid location") { - osmium::geom::GEOSFactory<> factory; - - REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location); -} - -TEST_CASE("GEOS geometry factory - create linestring") { - osmium::geom::GEOSFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - SECTION("from way node list") { - std::unique_ptr linestring {factory.create_linestring(wnl)}; - REQUIRE(3 == linestring->getNumPoints()); - - std::unique_ptr p0 = std::unique_ptr(linestring->getPointN(0)); - REQUIRE(3.2 == p0->getX()); - std::unique_ptr p2 = std::unique_ptr(linestring->getPointN(2)); - REQUIRE(3.6 == p2->getX()); - } - - SECTION("without duplicates and backwards") { - std::unique_ptr linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)}; - REQUIRE(3 == linestring->getNumPoints()); - std::unique_ptr p0 = std::unique_ptr(linestring->getPointN(0)); - REQUIRE(3.6 == p0->getX()); - std::unique_ptr p2 = std::unique_ptr(linestring->getPointN(2)); - REQUIRE(3.2 == p2->getX()); - } - - SECTION("with duplicates") { - std::unique_ptr linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(4 == linestring->getNumPoints()); - std::unique_ptr p0 = std::unique_ptr(linestring->getPointN(0)); - REQUIRE(3.2 == p0->getX()); - } - - SECTION("with duplicates and backwards") { - std::unique_ptr linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(4 == linestring->getNumPoints()); - std::unique_ptr p0 = std::unique_ptr(linestring->getPointN(0)); - REQUIRE(3.6 == p0->getX()); - } -} - -TEST_CASE("GEOS geometry factory - create area with one outer and no inner rings") { - osmium::geom::GEOSFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {3.2, 4.2}}, - {2, {3.5, 4.7}}, - {3, {3.6, 4.9}}, - {1, {3.2, 4.2}} - }} - }); - - std::unique_ptr mp {factory.create_multipolygon(area)}; - REQUIRE(1 == mp->getNumGeometries()); - - const geos::geom::Polygon* p0 = dynamic_cast(mp->getGeometryN(0)); - REQUIRE(0 == p0->getNumInteriorRing()); - - const geos::geom::LineString* l0e = p0->getExteriorRing(); - REQUIRE(4 == l0e->getNumPoints()); - - std::unique_ptr l0e_p0 = std::unique_ptr(l0e->getPointN(1)); - REQUIRE(3.5 == l0e_p0->getX()); -} - -TEST_CASE("GEOS geometry factory - create area with one outer and one inner ring") { - osmium::geom::GEOSFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {8.0, 1.0}}, - {7, {8.0, 8.0}}, - {8, {1.0, 8.0}}, - {5, {1.0, 1.0}} - }} - }); - - std::unique_ptr mp {factory.create_multipolygon(area)}; - REQUIRE(1 == mp->getNumGeometries()); - - const geos::geom::Polygon* p0 = dynamic_cast(mp->getGeometryN(0)); - REQUIRE(1 == p0->getNumInteriorRing()); - - const geos::geom::LineString* l0e = p0->getExteriorRing(); - REQUIRE(5 == l0e->getNumPoints()); - - const geos::geom::LineString* l0i0 = p0->getInteriorRingN(0); - REQUIRE(5 == l0i0->getNumPoints()); -} - -TEST_CASE("GEOS geometry factory - create area with two outer and two inner rings") { - osmium::geom::GEOSFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {4.0, 1.0}}, - {7, {4.0, 4.0}}, - {8, {1.0, 4.0}}, - {5, {1.0, 1.0}} - }}, - { false, { - {10, {5.0, 5.0}}, - {11, {5.0, 7.0}}, - {12, {7.0, 7.0}}, - {10, {5.0, 5.0}} - }}, - { true, { - {100, {10.0, 10.0}}, - {101, {11.0, 10.0}}, - {102, {11.0, 11.0}}, - {103, {10.0, 11.0}}, - {100, {10.0, 10.0}} - }} - }); - - std::unique_ptr mp {factory.create_multipolygon(area)}; - REQUIRE(2 == mp->getNumGeometries()); - - const geos::geom::Polygon* p0 = dynamic_cast(mp->getGeometryN(0)); - REQUIRE(2 == p0->getNumInteriorRing()); - - const geos::geom::LineString* l0e = p0->getExteriorRing(); - REQUIRE(5 == l0e->getNumPoints()); - - const geos::geom::Polygon* p1 = dynamic_cast(mp->getGeometryN(1)); - REQUIRE(0 == p1->getNumInteriorRing()); - - const geos::geom::LineString* l1e = p1->getExteriorRing(); - REQUIRE(5 == l1e->getNumPoints()); -} - diff --git a/third_party/libosmium/test/t/geom/test_geos_wkb.cpp b/third_party/libosmium/test/t/geom/test_geos_wkb.cpp deleted file mode 100644 index 0f54427e5..000000000 --- a/third_party/libosmium/test/t/geom/test_geos_wkb.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include "catch.hpp" - -#include -#include -#include - -#include "../basic/helper.hpp" -#include "helper.hpp" - -TEST_CASE("WKB_Geometry_with_GEOS") { - -SECTION("point") { - osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory<> geos_factory; - - std::string wkb {wkb_factory.create_point(osmium::Location(3.2, 4.2))}; - - std::unique_ptr geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2)); - REQUIRE(geos_to_wkb(geos_point.get()) == wkb); -} - - -SECTION("linestring") { - osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory<> geos_factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - { - std::string wkb = wkb_factory.create_linestring(wnl); - std::unique_ptr geos = geos_factory.create_linestring(wnl); - REQUIRE(geos_to_wkb(geos.get()) == wkb); - } - - { - std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward); - std::unique_ptr geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward); - REQUIRE(geos_to_wkb(geos.get()) == wkb); - } - - { - std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all); - std::unique_ptr geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::all); - REQUIRE(geos_to_wkb(geos.get()) == wkb); - } - - { - std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward); - std::unique_ptr geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward); - REQUIRE(geos_to_wkb(geos.get()) == wkb); - } -} - -SECTION("area_1outer_0inner") { - osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory<> geos_factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {3.2, 4.2}}, - {2, {3.5, 4.7}}, - {3, {3.6, 4.9}}, - {1, {3.2, 4.2}} - }} - }); - - std::string wkb = wkb_factory.create_multipolygon(area); - std::unique_ptr geos = geos_factory.create_multipolygon(area); - REQUIRE(geos_to_wkb(geos.get()) == wkb); -} - -SECTION("area_1outer_1inner") { - osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory<> geos_factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {8.0, 1.0}}, - {7, {8.0, 8.0}}, - {8, {1.0, 8.0}}, - {5, {1.0, 1.0}} - }} - }); - - std::string wkb = wkb_factory.create_multipolygon(area); - std::unique_ptr geos = geos_factory.create_multipolygon(area); - REQUIRE(geos_to_wkb(geos.get()) == wkb); -} - -SECTION("area_2outer_2inner") { - osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory<> geos_factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {4.0, 1.0}}, - {7, {4.0, 4.0}}, - {8, {1.0, 4.0}}, - {5, {1.0, 1.0}} - }}, - { false, { - {10, {5.0, 5.0}}, - {11, {5.0, 7.0}}, - {12, {7.0, 7.0}}, - {10, {5.0, 5.0}} - }}, - { true, { - {100, {10.0, 10.0}}, - {101, {11.0, 10.0}}, - {102, {11.0, 11.0}}, - {103, {10.0, 11.0}}, - {100, {10.0, 10.0}} - }} - }); - - std::string wkb = wkb_factory.create_multipolygon(area); - std::unique_ptr geos = geos_factory.create_multipolygon(area); - REQUIRE(geos_to_wkb(geos.get()) == wkb); -} - -} - diff --git a/third_party/libosmium/test/t/geom/test_mercator.cpp b/third_party/libosmium/test/t/geom/test_mercator.cpp deleted file mode 100644 index cc16e55cf..000000000 --- a/third_party/libosmium/test/t/geom/test_mercator.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("Mercator") { - - SECTION("mercator_projection") { - osmium::geom::MercatorProjection projection; - REQUIRE(3857 == projection.epsg()); - REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string()); - } - - SECTION("low_level_mercator_functions") { - osmium::geom::Coordinates c1(17.839, -3.249); - osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1)); - REQUIRE(r1.x == Approx(c1.x).epsilon(0.000001)); - REQUIRE(r1.y == Approx(c1.y).epsilon(0.000001)); - - osmium::geom::Coordinates c2(-89.2, 15.915); - osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2)); - REQUIRE(r2.x == Approx(c2.x).epsilon(0.000001)); - REQUIRE(r2.y == Approx(c2.y).epsilon(0.000001)); - - osmium::geom::Coordinates c3(180.0, 85.0); - osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3)); - REQUIRE(r3.x == Approx(c3.x).epsilon(0.000001)); - REQUIRE(r3.y == Approx(c3.y).epsilon(0.000001)); - } - - SECTION("mercator_bounds") { - osmium::Location mmax(180.0, osmium::geom::MERCATOR_MAX_LAT); - osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax); - REQUIRE(c.x == Approx(c.y).epsilon(0.001)); - REQUIRE(osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0)) == Approx(osmium::geom::MERCATOR_MAX_LAT).epsilon(0.0000001)); - } - -} diff --git a/third_party/libosmium/test/t/geom/test_ogr.cpp b/third_party/libosmium/test/t/geom/test_ogr.cpp deleted file mode 100644 index 28a10717d..000000000 --- a/third_party/libosmium/test/t/geom/test_ogr.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include "../basic/helper.hpp" - -TEST_CASE("OGR_Geometry") { - -SECTION("point") { - osmium::geom::OGRFactory<> factory; - - std::unique_ptr point {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(3.2 == point->getX()); - REQUIRE(4.2 == point->getY()); -} - -SECTION("empty_point") { - osmium::geom::OGRFactory<> factory; - - REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location); -} - -SECTION("linestring") { - osmium::geom::OGRFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - { - std::unique_ptr linestring {factory.create_linestring(wnl)}; - REQUIRE(3 == linestring->getNumPoints()); - - REQUIRE(3.2 == linestring->getX(0)); - REQUIRE(3.6 == linestring->getX(2)); - } - - { - std::unique_ptr linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)}; - REQUIRE(3 == linestring->getNumPoints()); - - REQUIRE(3.6 == linestring->getX(0)); - REQUIRE(3.2 == linestring->getX(2)); - } - - { - std::unique_ptr linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(4 == linestring->getNumPoints()); - - REQUIRE(3.2 == linestring->getX(0)); - } - - { - std::unique_ptr linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(4 == linestring->getNumPoints()); - - REQUIRE(3.6 == linestring->getX(0)); - } -} - -SECTION("area_1outer_0inner") { - osmium::geom::OGRFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {3.2, 4.2}}, - {2, {3.5, 4.7}}, - {3, {3.6, 4.9}}, - {1, {3.2, 4.2}} - }} - }); - - std::unique_ptr mp {factory.create_multipolygon(area)}; - REQUIRE(1 == mp->getNumGeometries()); - - const OGRPolygon* p0 = dynamic_cast(mp->getGeometryRef(0)); - REQUIRE(0 == p0->getNumInteriorRings()); - - const OGRLineString* l0e = p0->getExteriorRing(); - REQUIRE(4 == l0e->getNumPoints()); - - REQUIRE(3.5 == l0e->getX(1)); -} - -SECTION("area_1outer_1inner") { - osmium::geom::OGRFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {8.0, 1.0}}, - {7, {8.0, 8.0}}, - {8, {1.0, 8.0}}, - {5, {1.0, 1.0}} - }} - }); - - std::unique_ptr mp {factory.create_multipolygon(area)}; - REQUIRE(1 == mp->getNumGeometries()); - - const OGRPolygon* p0 = dynamic_cast(mp->getGeometryRef(0)); - REQUIRE(1 == p0->getNumInteriorRings()); - - const OGRLineString* l0e = p0->getExteriorRing(); - REQUIRE(5 == l0e->getNumPoints()); - - const OGRLineString* l0i0 = p0->getInteriorRing(0); - REQUIRE(5 == l0i0->getNumPoints()); -} - -SECTION("area_2outer_2inner") { - osmium::geom::OGRFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {4.0, 1.0}}, - {7, {4.0, 4.0}}, - {8, {1.0, 4.0}}, - {5, {1.0, 1.0}} - }}, - { false, { - {10, {5.0, 5.0}}, - {11, {5.0, 7.0}}, - {12, {7.0, 7.0}}, - {10, {5.0, 5.0}} - }}, - { true, { - {100, {10.0, 10.0}}, - {101, {11.0, 10.0}}, - {102, {11.0, 11.0}}, - {103, {10.0, 11.0}}, - {100, {10.0, 10.0}} - }} - }); - - std::unique_ptr mp {factory.create_multipolygon(area)}; - REQUIRE(2 == mp->getNumGeometries()); - - const OGRPolygon* p0 = dynamic_cast(mp->getGeometryRef(0)); - REQUIRE(2 == p0->getNumInteriorRings()); - - const OGRLineString* l0e = p0->getExteriorRing(); - REQUIRE(5 == l0e->getNumPoints()); - - const OGRPolygon* p1 = dynamic_cast(mp->getGeometryRef(1)); - REQUIRE(0 == p1->getNumInteriorRings()); - - const OGRLineString* l1e = p1->getExteriorRing(); - REQUIRE(5 == l1e->getNumPoints()); -} - -} - diff --git a/third_party/libosmium/test/t/geom/test_projection.cpp b/third_party/libosmium/test/t/geom/test_projection.cpp deleted file mode 100644 index 58854109e..000000000 --- a/third_party/libosmium/test/t/geom/test_projection.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include -#include - -TEST_CASE("Projection") { - -SECTION("identity_projection") { - osmium::geom::IdentityProjection projection; - REQUIRE(4326 == projection.epsg()); - REQUIRE("+proj=longlat +datum=WGS84 +no_defs" == projection.proj_string()); -} - -SECTION("project_location_4326") { - osmium::geom::Projection projection(4326); - REQUIRE(4326 == projection.epsg()); - REQUIRE("+init=epsg:4326" == projection.proj_string()); - - const osmium::Location loc(1.0, 2.0); - const osmium::geom::Coordinates c {1.0, 2.0}; - REQUIRE(c == projection(loc)); -} - -SECTION("project_location_4326_string") { - osmium::geom::Projection projection("+init=epsg:4326"); - REQUIRE(-1 == projection.epsg()); - REQUIRE("+init=epsg:4326" == projection.proj_string()); - - const osmium::Location loc(1.0, 2.0); - const osmium::geom::Coordinates c {1.0, 2.0}; - REQUIRE(c == projection(loc)); -} - -SECTION("unknown_projection_string") { - REQUIRE_THROWS_AS(osmium::geom::Projection projection("abc"), osmium::projection_error); -} - -SECTION("unknown_epsg_code") { - REQUIRE_THROWS_AS(osmium::geom::Projection projection(9999999), osmium::projection_error); -} - -SECTION("project_location_3857") { - osmium::geom::Projection projection(3857); - REQUIRE(3857 == projection.epsg()); - REQUIRE("+init=epsg:3857" == projection.proj_string()); - - { - const osmium::Location loc(0.0, 0.0); - const osmium::geom::Coordinates c {0.0, 0.0}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } - { - const osmium::Location loc(180.0, 0.0); - const osmium::geom::Coordinates c {20037508.34, 0.0}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } - { - const osmium::Location loc(180.0, 0.0); - const osmium::geom::Coordinates c {20037508.34, 0.0}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } - { - const osmium::Location loc(0.0, 85.0511288); - const osmium::geom::Coordinates c {0.0, 20037508.34}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } -} - -SECTION("project_location_mercator") { - osmium::geom::MercatorProjection projection; - - { - const osmium::Location loc(0.0, 0.0); - const osmium::geom::Coordinates c {0.0, 0.0}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } - { - const osmium::Location loc(180.0, 0.0); - const osmium::geom::Coordinates c {20037508.34, 0.0}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } - { - const osmium::Location loc(180.0, 0.0); - const osmium::geom::Coordinates c {20037508.34, 0.0}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } - { - const osmium::Location loc(0.0, 85.0511288); - const osmium::geom::Coordinates c {0.0, 20037508.34}; - REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1)); - REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1)); - } -} - -SECTION("compare_mercators") { - osmium::geom::MercatorProjection projection_merc; - osmium::geom::Projection projection_3857(3857); - REQUIRE(3857 == projection_3857.epsg()); - REQUIRE("+init=epsg:3857" == projection_3857.proj_string()); - - { - const osmium::Location loc(4.2, 27.3); - REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1)); - REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1)); - } - { - const osmium::Location loc(160.789, -42.42); - REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1)); - REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1)); - } - { - const osmium::Location loc(-0.001, 0.001); - REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1)); - REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1)); - } - { - const osmium::Location loc(-85.2, -85.2); - REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1)); - REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1)); - } -} - -SECTION("compare_mercators") { - osmium::geom::MercatorProjection projection_merc; - osmium::geom::Projection projection_3857(3857); - - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> dis_x(-180.0, 180.0); - std::uniform_real_distribution<> dis_y(-90.0, 90.0); - - for (int n = 0; n < 100000; ++n) { - const osmium::Location loc(dis_x(gen), dis_y(gen)); - REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1)); - REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1)); - } -} - -} diff --git a/third_party/libosmium/test/t/geom/test_tile.cpp b/third_party/libosmium/test/t/geom/test_tile.cpp deleted file mode 100644 index e80cb9604..000000000 --- a/third_party/libosmium/test/t/geom/test_tile.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -#include "helper.hpp" - -#include "test_tile_data.hpp" - -TEST_CASE("Tile") { - - SECTION("x0.0 y0.0 zoom 0") { - osmium::Location l(0.0, 0.0); - - osmium::geom::Tile t(0, l); - - REQUIRE(t.x == 0); - REQUIRE(t.y == 0); - REQUIRE(t.z == 0); - } - - SECTION("x180.0 y90.0 zoom 0") { - osmium::Location l(180.0, 90.0); - - osmium::geom::Tile t(0, l); - - REQUIRE(t.x == 0); - REQUIRE(t.y == 0); - REQUIRE(t.z == 0); - } - - SECTION("x180.0 y90.0 zoom 4") { - osmium::Location l(180.0, 90.0); - - osmium::geom::Tile t(4, l); - - REQUIRE(t.x == (1 << 4) - 1); - REQUIRE(t.y == 0); - REQUIRE(t.z == 4); - } - - SECTION("x0.0 y0.0 zoom 4") { - osmium::Location l(0.0, 0.0); - - osmium::geom::Tile t(4, l); - - auto n = 1 << (4-1); - REQUIRE(t.x == n); - REQUIRE(t.y == n); - REQUIRE(t.z == 4); - } - - SECTION("equality") { - osmium::geom::Tile a(4, 3, 4); - osmium::geom::Tile b(4, 3, 4); - osmium::geom::Tile c(4, 4, 3); - REQUIRE(a == b); - REQUIRE(a != c); - REQUIRE(b != c); - } - - SECTION("order") { - osmium::geom::Tile a(2, 3, 4); - osmium::geom::Tile b(4, 3, 4); - osmium::geom::Tile c(4, 4, 3); - osmium::geom::Tile d(4, 4, 2); - REQUIRE(a < b); - REQUIRE(a < c); - REQUIRE(b < c); - REQUIRE(d < c); - } - - SECTION("tilelist") { - std::istringstream input_data(s); - while (input_data) { - double lon, lat; - uint32_t x, y, zoom; - input_data >> lon; - input_data >> lat; - input_data >> x; - input_data >> y; - input_data >> zoom; - - osmium::Location l(lon, lat); - osmium::geom::Tile t(zoom, l); - REQUIRE(t.x == x); - REQUIRE(t.y == y); - } - } - -} - diff --git a/third_party/libosmium/test/t/geom/test_tile_data.hpp b/third_party/libosmium/test/t/geom/test_tile_data.hpp deleted file mode 100644 index 8a22cfa51..000000000 --- a/third_party/libosmium/test/t/geom/test_tile_data.hpp +++ /dev/null @@ -1,477 +0,0 @@ - -#include - -static std::string s = R"(127.4864358 16.8380041 223904 118630 18 -163.1103174 39.4760232 121 48 7 --4.1372725 -22.5105386 31 36 6 -98.7193066 -36.2312406 1 1 1 -63.5773661 -13.47636 21 17 5 --88.4518148 37.9805485 260 395 10 --14.5903133 -28.2989812 3763 4767 13 --13.4971239 -34.4080035 14 19 5 --169.156223 -64.0900356 3 93 7 -27.1473191 -4.1993125 4713 4191 13 --160.9733129 54.3684314 13 81 8 -129.0194139 14.2576156 439 235 9 --69.5085993 -56.8253221 10057 22700 15 --77.8387486 18.1961517 1162 1837 12 --76.2695325 -18.2494296 147 282 9 --91.594905 7.6698071 1 3 3 --116.7926741 -20.6060813 179 571 10 -109.0552776 -1.9947569 52620 33131 16 --156.1846426 -79.3817554 33 449 9 --95.3403755 -27.8978407 1 4 3 --55.1827573 -73.2293796 44 103 7 --108.5207885 -48.0099293 50 167 8 -23.7540108 -15.3395164 9273 8898 14 --155.6662842 -68.3295899 0 0 0 -75.8139119 30.9914252 363 209 9 --135.8034544 64.7242469 0 1 2 --48.743352 70.9392876 23 13 6 --38.6968026 7.7867812 0 0 0 --18.5234838 11.8557704 29395 30594 16 --152.5632568 19.4069834 78 455 10 --63.2089431 -80.5909713 0 0 0 --94.1255611 -81.2028822 244 930 10 -175.0862205 -33.0865142 3 2 2 --179.6241926 -37.0256609 1 625 10 -135.6783824 -38.6011643 459739 323170 19 --139.6407533 -83.2495209 0 7 3 --14.1336447 -56.5465949 58 88 7 --30.7414568 -32.9543731 26 38 6 -10.3306861 73.2444693 1082 399 11 --84.8379263 29.2363222 16 26 6 --94.0685822 -39.5503996 7821 20309 15 --86.5944356 -41.7491891 265 642 10 -11.9182172 -80.5613703 34937 58784 16 -91.8773752 -32.1741317 0 0 0 -126.2879157 20.5759564 1742 904 11 --160.7743029 -47.3192128 27999 340565 19 --4.2449045 -50.3288332 31 42 6 --66.6857158 61.4380757 10 9 5 -169.7372317 -74.3365704 3 3 2 -87.4815328 75.6218888 95 21 7 -60.3544927 28.3165267 0 0 0 --48.9614619 -59.3292497 2 5 3 --123.2935018 -59.5454886 80 362 9 --31.5909316 -14.8985476 13 17 5 -58.1862173 59.0957666 2710 1209 12 --72.8881665 -2.2648849 1218 2073 12 --33.7267461 8.6006817 106512 124785 18 -175.723181 46.4929742 7 2 3 --127.1963326 76.0328786 0 0 0 --161.7444367 -26.7634497 13293 151310 18 --163.976298 -8.1169845 91 1070 11 -63.7757109 5.6049418 2 1 2 -12.7012434 22.1157713 70160 57276 17 -19.5832849 -25.0284049 1135 1171 11 --22.6619642 54.8831276 111 81 8 -78.7736907 24.0919863 5888 3530 13 -121.9003045 -64.6256685 107 94 7 --64.8766793 61.6655916 81 71 8 -113.0498445 -70.0016518 416 397 9 --51.5116259 68.1532424 46781 31217 17 --89.9005747 87.9523248 512 0 11 -59.2536822 -75.1520493 10 13 4 -17.375372 74.9259262 287448 93371 19 -75.6426945 8.4808632 186153 124873 18 -144.89589 75.1647661 14786 2875 14 -174.4350898 -29.268169 258091 153376 18 --91.8773113 50.6182166 0 0 0 -5.3822308 45.1391794 134991 94156 18 -43.0978373 -10.0764237 324909 276895 19 -55.6682917 -40.9015342 21451 20470 15 --37.584032 52.253723 6 5 4 -131.0141997 29.0271798 28309 13621 15 -69.8830721 -86.8548645 363918 524287 19 --107.7917548 -76.9626654 26290 110787 17 --57.1736642 49.9345991 2 2 3 -165.5170226 -84.9735363 982 1021 10 --139.7208984 -73.8754873 1 12 4 --154.5959463 -10.596718 4 33 6 --106.4164918 36.5042686 3348 6405 14 --92.9688259 -11.2262505 0 2 2 -138.2722283 8.1109779 7 3 3 -123.1389319 -40.3505677 862 637 10 --171.4780435 24.9112482 0 13 5 -89.3668763 -63.1809434 392293 381781 19 --79.6906176 -13.376312 9130 17612 15 -133.1329522 -28.9032634 445 298 9 -115.0369496 70.6965823 6 1 3 --74.8926697 -78.9770185 2391 7144 13 -51.9175766 73.0184277 164 50 8 -178.1319784 43.7111421 509 186 9 -162.4098389 61.1595443 0 0 0 -7.6241126 -75.6182944 2 3 2 -172.8902767 28.5068027 125 53 7 -156.4030739 -76.7309238 478 431 9 --131.3963189 62.2039684 1 2 3 -34.6057088 -36.2933264 2441 2491 12 --3.3896413 -48.2734347 15 20 5 -83.528842 -48.219886 2998 2675 12 -16.6000512 -31.6322244 17894 19421 15 --18.2425749 21.0749052 14 14 5 -35.6035336 46.9916228 78498 46105 17 --109.3453091 -34.2312523 12 38 6 -88.4909962 58.6104749 47 19 6 --129.7372783 21.7408241 571 1794 12 -25.7269392 -40.1240139 1 1 1 -26.3829579 5.248998 37570 31811 16 -141.1768247 -41.4653038 14617 10269 14 -151.3788752 -38.0160512 241302 161042 18 --92.7471483 -35.391745 15883 39664 16 -142.5902623 -14.1023743 28 17 5 -179.3461485 -86.7573357 3 3 2 --40.9746194 61.5689546 790 576 11 -128.6399735 -54.8895009 56186 44772 16 --141.391583 -63.8272 0 2 2 --3.5004218 19.3089998 4016 3648 13 -16.138208 -42.7868627 1 1 1 -78.502315 -18.91667 2 2 2 --44.6311826 -15.7483106 98572 142686 18 --120.431941 -39.3431529 0 0 0 --70.4915024 25.4763412 9967 13984 15 -118.0711114 -66.5691073 211 192 8 --114.945538 38.1764389 0 0 0 -142.991315 -46.3378741 14699 10577 14 -34.2770562 -84.7173756 312063 518834 19 -109.5563415 -85.9138266 105424 131071 17 --171.8032643 70.1948223 0 3 4 --90.8434294 89.7252122 126 0 9 -163.5677082 -53.9885419 3 2 2 -128.884016 -63.0732584 112461 95358 17 -116.5348575 -56.1616143 843 705 10 --171.5770602 37.9225943 11 197 9 -48.1396653 -49.3932234 5191 5392 13 --157.6786731 15.3895763 32507 239456 19 -15.7385145 -37.1364397 1113 1251 11 -137.5179466 61.2025671 1 0 1 --70.4767722 42.9798424 19938 24086 16 -27.8867901 43.4642562 9461 5991 14 -68.5677462 -84.9560937 11312 16334 14 --56.790151 -67.124147 179437 395476 19 -108.850832 43.3493384 26291 11996 15 --139.0655153 8.2673118 1 7 4 -59.3726661 83.3857699 21788 1515 15 --158.4718709 -12.2313178 1 17 5 -30.358316 -83.020501 2393 3871 12 --169.9667863 71.1152107 1 13 6 --89.9418297 -7.7258969 131156 273429 19 --16.5050312 47.1843923 116 89 8 --151.9641886 -36.3579042 5103 39881 16 -169.7406916 60.0950674 62 18 6 -32.6694543 -1.8435981 2 2 2 -97.7880811 77.5295169 50569 9674 16 -87.7554889 -85.6741368 389947 524287 19 --19.0174909 29.1940122 0 0 1 --86.6180019 82.6445919 1 0 2 --50.1997802 -21.1913243 1476 2294 12 -73.8710121 75.2201385 5 1 3 -41.7434624 79.1410045 322937 65770 19 --122.4312562 -68.4513916 10 48 6 --54.6116448 -23.1761137 1 2 2 --35.8774263 -51.5317442 102 170 8 -179.2976644 -76.2729885 127 107 7 --111.6934402 -85.2696836 1 7 3 --24.2137947 28.4102025 3 3 3 --168.0816395 -64.0317696 16 375 9 -43.2514876 6.4266793 2540 1974 12 -25.5877932 49.3486828 4 2 3 --133.3671657 -25.0795973 8 36 6 --140.2002274 -37.3713396 452 2507 12 -73.6326557 -21.9898207 360 288 9 --83.0901448 -69.1893461 2205 6305 13 --32.83227 -11.1061854 3348 4350 13 --151.8897244 14.6891958 0 0 0 --118.1125151 82.3085937 704 288 12 -119.9903922 1.4884267 53 31 6 --116.9455865 -48.1971821 0 2 2 -111.4279587 -52.6024326 828 688 10 --78.9207774 28.6183104 147207 218615 19 -45.1367631 24.1416251 40 27 6 -115.0905685 7.2971256 6714 3929 13 --58.0837371 -55.4033522 43 87 7 --44.6785779 83.0751777 6158 877 14 -80.2002966 84.3087089 2960 91 12 --167.3118039 -59.2698371 72 1445 11 -139.9974902 -74.5994693 455 419 9 --27.5858357 -36.1890547 6936 9960 14 -68.8572424 20.2096749 353 226 9 --168.7172825 69.1607462 2053 15104 16 -62.1361934 74.6007777 44079 11896 16 --102.9645124 65.3735325 112191 135144 19 -178.8434887 18.6231394 65325 29316 16 --138.0494072 -80.3786289 29 228 8 -33.3858934 62.9029909 155382 71699 18 --1.6915643 74.737228 1 0 2 -18.2680756 6.6441482 1 0 1 -34.0511738 -28.6862516 2 2 2 --24.0705994 -0.6026568 28386 32877 16 --176.8765092 -14.3252022 568 35403 16 -154.6553417 -79.7390666 1903 1809 11 -151.6055263 59.552346 14 4 4 --101.7681729 45.3498263 113933 187876 19 --52.3703658 -89.8260406 181 511 9 --85.7937259 16.5632413 2143 3713 13 -114.7030999 6.6846014 104 61 7 -13.6027861 88.6863877 2 0 2 -60.5726928 38.256536 43794 25219 16 -141.0903381 -35.4468007 7306 4959 13 --38.8182454 -55.2332792 200 350 9 -179.7818018 -79.6600052 523970 462627 19 --45.2102175 82.7381225 196301 32058 19 --36.5811826 -35.3991346 0 0 0 --26.7719575 -75.7014102 223154 435372 19 -77.3451937 -65.4613594 1 1 1 --37.3286225 38.3250599 51945 50407 17 -70.8235495 35.3870419 365288 206979 19 -99.8381373 -83.4101655 1 1 1 -25.8851923 67.415543 9370 3991 14 --12.3393758 68.5972027 7 3 4 --142.9400273 -36.2904852 1 9 4 -110.085689 -50.9514972 422467 348655 19 -121.5093657 53.9939447 54888 21044 16 -151.1307841 -33.0798435 58 38 6 -100.4346499 -57.0129759 6 5 3 -114.0564882 63.4987339 428250 141474 19 --17.3978586 19.2981593 57 57 7 --129.101039 -66.3423574 579 3067 12 -117.6639917 14.0568892 433504 241463 19 -97.7014577 69.1261732 202216 60490 18 --174.7931333 81.4174709 7583 46045 19 -47.205341 -48.8608019 20680 21495 15 -167.416796 -7.5063098 247 133 8 -63.6744589 21.3392888 0 0 0 --106.0719817 33.8353547 53832 104862 18 --48.4051268 27.0438152 191648 221209 19 -64.5675545 -27.0683253 5 4 3 -110.7800249 -35.8217841 0 0 0 -164.8954138 81.9558801 31393 2538 15 --54.4595565 -23.0128432 357 579 10 -43.2542709 67.694011 2540 989 12 -137.6537233 -78.7052092 28913 28450 15 -76.9271563 -60.0777348 0 0 0 --145.0240216 47.3869213 6367 22947 16 -136.2328853 -73.4534547 3598 3304 12 -48.8047148 74.3001023 81 23 7 --144.6978756 33.6270048 200 820 11 -64.6723407 -37.196427 21 19 5 --58.3356482 -19.0812366 22148 36307 16 -19.611535 -31.3013119 0 0 0 --63.8923439 -25.9560287 1 2 2 --152.5288047 -30.9747477 0 1 1 --99.8509683 -69.0258965 7295 25181 15 --22.9015207 -21.0915082 13 17 5 -161.4402438 61.1430241 15539 4652 14 --102.9499976 -1.2629414 1 4 3 --159.7995801 51.1570142 14 85 8 -10.5265485 -86.8526122 67 127 7 -47.1581041 -73.1628608 646 823 10 -2.7577906 -66.3257104 66540 98133 17 -96.9653593 -9.8258675 6 4 3 --55.4199846 25.3325116 2834 3499 13 --47.3590106 59.5085133 2 2 3 -179.1441501 22.1324479 7 3 3 -16.2649007 47.8480398 4 2 3 --27.8373963 -0.3926597 27700 32839 16 --99.7938802 -48.8013068 912 2685 12 -133.4858024 28.457146 3 1 2 --174.7621207 -25.8318084 238 9409 14 -106.856378 19.640472 203 113 8 -31.4361995 -80.2488406 76981 116886 17 -148.6539554 -70.0347611 116 99 7 -45.1821773 17.5961595 80 57 7 --30.3630114 71.3238998 54481 27877 17 -106.547704 44.9731358 6520 2947 13 --132.8057564 23.3928795 67 221 9 -116.6455816 -10.1097592 52 33 6 -172.5512559 -53.2307289 3 2 2 --114.2084519 42.834332 2994 6030 14 -91.0172087 87.6025 1 0 1 --101.666812 -84.7858729 7130 32495 15 --14.8074931 68.3277393 0 0 0 -140.3354277 -7.8709618 14 8 4 --130.4961987 -69.4777523 9011 50594 16 --121.239479 1.0896367 1 3 3 --141.2241052 3.4495348 56471 257117 19 -42.6041377 -19.1328846 2532 2269 12 -141.3750885 -1.8110503 468036 264781 19 --26.545021 -30.9641274 218 302 9 -87.6154866 10.1978751 5 3 3 -88.002559 -33.4108714 762 612 10 -170.9910642 -7.1925019 3993 2130 12 --66.5680487 -88.1144993 165197 524287 19 --71.5925378 45.720316 0 0 0 --16.457642 57.1688038 930 625 11 -20.8379624 -11.1485568 35 33 6 --72.9399538 -16.6504502 1 2 2 -52.8746845 -71.5213577 10598 12927 14 -93.2392918 12.5073156 48 29 6 --3.7803834 73.7748237 128319 49794 18 -93.5713795 -38.8308882 24 19 5 -87.3474619 -6.9970464 23 16 5 -161.2199467 48.5612779 30 11 5 -87.343969 -31.3153618 47 37 6 -60.5318627 58.0869948 42 19 6 -161.4388458 42.7612385 1 0 1 -14.1262999 -26.2101142 4 4 3 --135.776346 -21.4248586 503 2297 12 --100.3980364 82.0236388 1 0 3 --55.8093833 -87.2455194 0 0 0 --15.6397352 64.454076 935 540 11 -131.5974423 39.1251372 110 48 7 -56.8045509 27.5658629 168 107 8 -146.3634996 14.9287416 3 1 2 -51.5699041 74.0370231 82 23 7 -29.3100901 33.7208834 152414 104963 18 -19.0622442 1.6781772 141 126 8 --22.2575472 73.6467471 114864 50126 18 -125.0208495 47.8533914 3470 1426 12 --92.4804503 29.8409387 995 1691 12 -113.6362202 86.1158625 0 0 0 -113.6203756 28.4267778 26 13 5 -124.472202 25.8347062 13856 6974 14 -79.3654306 -33.7864728 46 38 6 --121.169233 -66.7642843 2 12 4 -179.5816311 1.0182064 0 0 0 -179.1123794 53.367624 0 0 0 --25.6611689 32.6575586 14048 13236 15 -92.3370554 58.8306651 12 4 4 -142.2756448 63.6603101 3 1 2 --162.8914282 -84.54406 6229 129034 17 --54.0759935 53.1086102 0 0 0 -9.1647045 -39.4876873 34436 40604 16 -59.3708822 -43.9789068 10894 10425 14 --16.6397572 46.5985252 929 723 11 --36.1053642 -67.6882841 0 1 1 --82.5851985 -69.5277766 4 12 4 -117.0059969 -63.2697116 432546 382068 19 -127.9740251 85.5341901 112129 0 17 --13.9255265 59.7720207 120931 76457 18 --167.7778382 41.7974194 69 761 11 --100.1217856 -70.5624949 454 1599 11 --42.4790343 -2.0016191 25034 33132 16 --8.0782317 65.9680074 30 16 6 --37.0481466 -55.2856125 203 350 9 -149.074382 16.7121888 58 28 6 --53.1010518 -15.8492068 0 0 0 -50.8517919 -30.8366257 42025 38674 16 --175.0355994 77.1929422 0 4 5 --33.3221217 72.5636809 6 3 4 --139.9201802 52.3400823 7296 21546 16 -86.0299659 23.4535286 1513 886 11 -105.6297238 -50.5521342 25998 21733 15 -104.2700533 36.5417507 206999 102450 18 -58.5238253 84.0320186 86843 3912 17 --121.9177826 65.4393267 1321 2108 13 --152.689211 57.4112922 39774 159515 19 -94.2583831 80.8625455 6240 801 13 -118.8199874 -37.6116567 53 39 6 -5.787144 7.0599251 4227 3934 13 -152.1682213 11.778732 236 119 8 -37.4503636 64.311498 2474 1084 12 -35.2616139 -59.8196291 38 45 6 --20.2808572 -26.9983008 29075 37875 16 --88.8541607 -20.4896703 66370 146320 18 -125.7726709 41.2603793 27 11 5 --55.4322696 22.1767236 11338 14313 15 --38.2393439 -56.4681037 6 11 4 --139.4517643 -81.3621632 3 29 5 --146.7954207 -74.6050826 6044 53642 16 -161.6654898 -71.7313805 15549 12957 14 --85.4720514 -73.177675 2 6 3 --25.7457381 -42.9842376 13 20 5 --2.0766311 51.0142455 0 0 1 --82.9179334 1.4865326 8836 16248 15 -140.5661302 61.5056993 28 9 5 --30.2614099 35.5786378 54518 51659 17 --49.2072142 -38.6965571 0 1 1 -124.6587534 9.5039576 433 242 9 --113.4516741 81.4585593 24229 11410 17 --4.5134723 68.229217 3 1 3 -75.4838529 -44.997406 2906 2622 12 -6.4715239 28.6900832 8486 6828 14 -91.9187555 -24.8192643 6187 4679 13 --28.2510181 -42.6238777 26 40 6 --151.1042237 -21.4553189 2630 18384 15 --149.6272551 0.4235911 1382 8172 14 --51.9171488 74.630423 0 0 0 --36.5660117 37.242858 101 99 8 -91.7136677 -30.9077617 772 604 10 -61.6846009 -85.9378164 5 7 3 -11.3772008 69.40183 34839 14980 16 -82.6825938 9.4496443 11954 7759 14 -61.8446231 -40.0114106 2751 2545 12 --51.6223196 -11.7880324 5 8 4 -113.0309076 -73.4376173 13336 13217 14 --169.3808275 -72.7209175 0 25 5 --98.5653414 -80.0893122 231 910 10 --20.4653707 29.9801495 3 3 3 -78.9156686 2.599349 0 0 0 -76.0635255 -71.0823347 2913 3216 12 --26.1185551 22.3616029 28013 28589 16 -177.8803853 -56.3662368 4071 2828 12 --157.7926463 78.4998022 15 34 8 -168.6834344 -34.5535211 7934 4934 13 --77.208013 -44.0964079 0 1 1 --56.6162078 28.1240365 10 13 5 -8.6548899 72.178831 137374 53767 18 --27.9342497 8.2525327 1 1 2 -91.6356971 -13.5230128 6181 4406 13 --161.9980398 -75.4443511 0 13 4 -46.8556576 -27.1078679 5162 4737 13 -147.2806954 -48.1491071 465 334 9 --168.2679875 -29.0171568 0 2 2 -10.0251187 -3.144812 8 8 4 -109.0281873 81.9713348 26307 2528 15 --129.6281276 -36.9614028 73359 320148 19 -7.3831244 -18.3270273 2132 2260 12 --34.4625217 53.2837646 52988 42524 17 -129.8855275 -26.30807 3525 2358 12 --69.6374195 -45.7769025 10045 21081 15 -59.9868336 50.3716565 43688 22120 16 -126.4653338 -75.607391 1743 1698 11 --34.6459616 53.2502443 51 41 7 -152.2415169 -71.7528837 1 1 1 --83.2126752 32.6685119 35239 52939 17 -178.6388805 70.5727365 31 7 5 --153.5646223 -81.9491561 2 29 5 -178.2668159 11.8222247 0 0 0 --27.136902 18.4287365 6 7 4 --104.7744923 -64.7769211 54777 193540 18 -58.2318889 9.5897974 2710 1938 12 -138.9707487 -65.2734433 14516 12149 14 --115.29331 -84.3402223 2944 16033 14 --66.3487123 -81.8340211 20 58 6 -76.1802855 40.4007156 364 193 9 --77.5026834 -30.653231 145 301 9 --52.6095007 -79.7155889 11595 28942 15 --2.5594899 -31.6276806 7 9 4 --58.6267217 41.4851391 2 2 3 --0.7245205 -70.7329433 509 801 10 -161.2822996 -79.0311957 124257 114418 17 -144.8720197 80.1059269 14785 1811 14 -159.3764075 -23.5100054 0 0 0 -82.3109493 -7.0673699 95504 68115 17 -94.3931949 63.0474034 97 34 7 -87.4523391 -73.2690527 3043 3297 12 -101.4256455 -0.8267694 12 8 4 --112.7666152 -82.3670281 12239 61007 16 --82.0948447 -38.0810449 8 19 5 -113.2906728 -19.193243 104 70 7 -16.953131 78.402684 35 8 6 --81.7974685 -53.9596787 34 86 7 -69.8051889 58.1416894 181902 78760 18 --9.2435464 -53.4296594 3 5 3 -30.0415066 11.4884737 4 3 3 -125.2704157 -69.6324197 54 49 6 --41.2060435 63.8501787 789 548 11 -120.407662 -4.9889504 6835 4209 13 -92.0345558 -8.0809262 24761 17121 15 -127.1061722 83.1311204 6988 428 13 --178.9414629 64.0086678 770 69897 18 -49.0743035 -4.3000419 10425 8387 14 --45.109002 -55.1435498 1534 2803 12 -3.2795498 75.95918 32 10 6 -)"; - diff --git a/third_party/libosmium/test/t/geom/test_wkb.cpp b/third_party/libosmium/test/t/geom/test_wkb.cpp deleted file mode 100644 index 730ee75ad..000000000 --- a/third_party/libosmium/test/t/geom/test_wkb.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include "../basic/helper.hpp" - -#if __BYTE_ORDER == __LITTLE_ENDIAN - -TEST_CASE("WKB_Geometry_byte_order_dependent") { - -SECTION("point") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - - std::string wkb {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string{"01010000009A99999999990940CDCCCCCCCCCC1040"} == wkb); -} - -SECTION("point_ewkb") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex); - - std::string wkb {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string{"0101000020E61000009A99999999990940CDCCCCCCCCCC1040"} == wkb); -} - -SECTION("linestring") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - { - std::string wkb {factory.create_linestring(wnl)}; - REQUIRE(std::string{"0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == wkb); - } - - { - std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)}; - REQUIRE(std::string{"010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040"} == wkb); - } - - { - std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(std::string{"0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == wkb); - } - - { - std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(std::string{"010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040"} == wkb); - } -} - -SECTION("linestring_ewkb") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex); - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - std::string ewkb {factory.create_linestring(wnl)}; - REQUIRE(std::string{"0102000020E6100000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == ewkb); -} - -SECTION("linestring_with_two_same_locations") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.5, 4.7}}, - {2, {3.5, 4.7}} - }); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error); - - { - std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(std::string{"0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240"} == wkb); - } - - { - std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(std::string{"0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240"} == wkb); - } -} - -SECTION("linestring_with_undefined_location") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.5, 4.7}}, - {2, osmium::Location()} - }); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location); -} - -} - -#endif - -TEST_CASE("WKB_Geometry_byte_order_independent") { - -SECTION("empty_point") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - - REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location); -} - -SECTION("empty_linestring") { - osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, {}); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error); -} - -} - diff --git a/third_party/libosmium/test/t/geom/test_wkt.cpp b/third_party/libosmium/test/t/geom/test_wkt.cpp deleted file mode 100644 index 538307409..000000000 --- a/third_party/libosmium/test/t/geom/test_wkt.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include "../basic/helper.hpp" - -TEST_CASE("WKT_Geometry") { - -SECTION("point") { - osmium::geom::WKTFactory<> factory; - - std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string{"POINT(3.2 4.2)"} == wkt); -} - -SECTION("empty_point") { - osmium::geom::WKTFactory<> factory; - - REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location); -} - -SECTION("linestring") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.2, 4.2}}, - {3, {3.5, 4.7}}, - {4, {3.5, 4.7}}, - {2, {3.6, 4.9}} - }); - - { - std::string wkt {factory.create_linestring(wnl)}; - REQUIRE(std::string{"LINESTRING(3.2 4.2,3.5 4.7,3.6 4.9)"} == wkt); - } - - { - std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)}; - REQUIRE(std::string{"LINESTRING(3.6 4.9,3.5 4.7,3.2 4.2)"} == wkt); - } - - { - std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(std::string{"LINESTRING(3.2 4.2,3.5 4.7,3.5 4.7,3.6 4.9)"} == wkt); - } - - { - std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(std::string{"LINESTRING(3.6 4.9,3.5 4.7,3.5 4.7,3.2 4.2)"} == wkt); - } -} - -SECTION("empty_linestring") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, {}); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error); - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error); -} - -SECTION("linestring_with_two_same_locations") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.5, 4.7}}, - {2, {3.5, 4.7}} - }); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error); - - try { - factory.create_linestring(wnl); - } catch (osmium::geometry_error& e) { - REQUIRE(e.id() == 0); - REQUIRE(std::string(e.what()) == "need at least two points for linestring"); - } - - REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error); - - { - std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all)}; - REQUIRE(std::string{"LINESTRING(3.5 4.7,3.5 4.7)"} == wkt); - } - - { - std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)}; - REQUIRE(std::string{"LINESTRING(3.5 4.7,3.5 4.7)"} == wkt); - } -} - -SECTION("linestring_with_undefined_location") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - auto& wnl = osmium::builder::build_way_node_list(buffer, { - {1, {3.5, 4.7}}, - {2, osmium::Location()} - }); - - REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location); -} - -SECTION("area_1outer_0inner") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {3.2, 4.2}}, - {2, {3.5, 4.7}}, - {3, {3.6, 4.9}}, - {1, {3.2, 4.2}} - }} - }); - - { - std::string wkt {factory.create_multipolygon(area)}; - REQUIRE(std::string{"MULTIPOLYGON(((3.2 4.2,3.5 4.7,3.6 4.9,3.2 4.2)))"} == wkt); - } -} - -SECTION("area_1outer_1inner") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {8.0, 1.0}}, - {7, {8.0, 8.0}}, - {8, {1.0, 8.0}}, - {5, {1.0, 1.0}} - }} - }); - - { - std::string wkt {factory.create_multipolygon(area)}; - REQUIRE(std::string{"MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,8 1,8 8,1 8,1 1)))"} == wkt); - } -} - -SECTION("area_2outer_2inner") { - osmium::geom::WKTFactory<> factory; - - osmium::memory::Buffer buffer(10000); - osmium::Area& area = buffer_add_area(buffer, - "foo", - {}, - { - { true, { - {1, {0.1, 0.1}}, - {2, {9.1, 0.1}}, - {3, {9.1, 9.1}}, - {4, {0.1, 9.1}}, - {1, {0.1, 0.1}} - }}, - { false, { - {5, {1.0, 1.0}}, - {6, {4.0, 1.0}}, - {7, {4.0, 4.0}}, - {8, {1.0, 4.0}}, - {5, {1.0, 1.0}} - }}, - { false, { - {10, {5.0, 5.0}}, - {11, {5.0, 7.0}}, - {12, {7.0, 7.0}}, - {10, {5.0, 5.0}} - }}, - { true, { - {100, {10.0, 10.0}}, - {101, {11.0, 10.0}}, - {102, {11.0, 11.0}}, - {103, {10.0, 11.0}}, - {100, {10.0, 10.0}} - }} - }); - - { - std::string wkt {factory.create_multipolygon(area)}; - REQUIRE(std::string{"MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,4 1,4 4,1 4,1 1),(5 5,5 7,7 7,5 5)),((10 10,11 10,11 11,10 11,10 10)))"} == wkt); - } -} - -} - diff --git a/third_party/libosmium/test/t/index/test_id_to_location.cpp b/third_party/libosmium/test/t/index/test_id_to_location.cpp deleted file mode 100644 index 4aca238b6..000000000 --- a/third_party/libosmium/test/t/index/test_id_to_location.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -template -void test_func_all(TIndex& index) { - osmium::unsigned_object_id_type id1 = 12; - osmium::unsigned_object_id_type id2 = 3; - osmium::Location loc1(1.2, 4.5); - osmium::Location loc2(3.5, -7.2); - - REQUIRE_THROWS_AS(index.get(id1), osmium::not_found); - - index.set(id1, loc1); - index.set(id2, loc2); - - index.sort(); - - REQUIRE_THROWS_AS(index.get(5), osmium::not_found); - REQUIRE_THROWS_AS(index.get(100), osmium::not_found); -} - -template -void test_func_real(TIndex& index) { - osmium::unsigned_object_id_type id1 = 12; - osmium::unsigned_object_id_type id2 = 3; - osmium::Location loc1(1.2, 4.5); - osmium::Location loc2(3.5, -7.2); - - index.set(id1, loc1); - index.set(id2, loc2); - - index.sort(); - - REQUIRE(loc1 == index.get(id1)); - REQUIRE(loc2 == index.get(id2)); - - REQUIRE_THROWS_AS(index.get(5), osmium::not_found); - REQUIRE_THROWS_AS(index.get(100), osmium::not_found); - - index.clear(); - - REQUIRE_THROWS_AS(index.get(id1), osmium::not_found); -} - -TEST_CASE("IdToLocation") { - - SECTION("Dummy") { - typedef osmium::index::map::Dummy index_type; - - index_type index1; - - REQUIRE(0 == index1.size()); - REQUIRE(0 == index1.used_memory()); - - test_func_all(index1); - - REQUIRE(0 == index1.size()); - REQUIRE(0 == index1.used_memory()); - } - - SECTION("DenseMemArray") { - typedef osmium::index::map::DenseMemArray index_type; - - index_type index1; - index1.reserve(1000); - test_func_all(index1); - - index_type index2; - index2.reserve(1000); - test_func_real(index2); - } - -#ifdef __linux__ - SECTION("DenseMmapArray") { - typedef osmium::index::map::DenseMmapArray index_type; - - index_type index1; - test_func_all(index1); - - index_type index2; - test_func_real(index2); - } -#else -# pragma message("not running 'DenseMapMmap' test case on this machine") -#endif - - SECTION("DenseFileArray") { - typedef osmium::index::map::DenseFileArray index_type; - - index_type index1; - test_func_all(index1); - - index_type index2; - test_func_real(index2); - } - -#ifdef OSMIUM_WITH_SPARSEHASH - - SECTION("SparseMemTable") { - typedef osmium::index::map::SparseMemTable index_type; - - index_type index1; - test_func_all(index1); - - index_type index2; - test_func_real(index2); - } - -#endif - - SECTION("SparseMemMap") { - typedef osmium::index::map::SparseMemMap index_type; - - index_type index1; - test_func_all(index1); - - index_type index2; - test_func_real(index2); - } - - SECTION("SparseMemArray") { - typedef osmium::index::map::SparseMemArray index_type; - - index_type index1; - - REQUIRE(0 == index1.size()); - REQUIRE(0 == index1.used_memory()); - - test_func_all(index1); - - REQUIRE(2 == index1.size()); - - index_type index2; - test_func_real(index2); - } - - SECTION("Dynamic map choice") { - typedef osmium::index::map::Map map_type; - const auto& map_factory = osmium::index::MapFactory::instance(); - - std::vector map_type_names = map_factory.map_types(); - REQUIRE(map_type_names.size() >= 5); - - for (const auto& map_type_name : map_type_names) { - std::unique_ptr index1 = map_factory.create_map(map_type_name); - index1->reserve(1000); - test_func_all(*index1); - - std::unique_ptr index2 = map_factory.create_map(map_type_name); - index2->reserve(1000); - test_func_real(*index2); - } - } - -} - diff --git a/third_party/libosmium/test/t/io/data.osm b/third_party/libosmium/test/t/io/data.osm deleted file mode 100644 index fffb77ad3..000000000 --- a/third_party/libosmium/test/t/io/data.osm +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/third_party/libosmium/test/t/io/data.osm.bz2 b/third_party/libosmium/test/t/io/data.osm.bz2 deleted file mode 100644 index 0f38797eb..000000000 Binary files a/third_party/libosmium/test/t/io/data.osm.bz2 and /dev/null differ diff --git a/third_party/libosmium/test/t/io/data.osm.gz b/third_party/libosmium/test/t/io/data.osm.gz deleted file mode 100644 index 07edb9095..000000000 Binary files a/third_party/libosmium/test/t/io/data.osm.gz and /dev/null differ diff --git a/third_party/libosmium/test/t/io/data_bzip2.txt b/third_party/libosmium/test/t/io/data_bzip2.txt deleted file mode 100644 index 755d6af45..000000000 --- a/third_party/libosmium/test/t/io/data_bzip2.txt +++ /dev/null @@ -1 +0,0 @@ -TESTDATA diff --git a/third_party/libosmium/test/t/io/data_bzip2.txt.bz2 b/third_party/libosmium/test/t/io/data_bzip2.txt.bz2 deleted file mode 100644 index f0ee7e7d6..000000000 Binary files a/third_party/libosmium/test/t/io/data_bzip2.txt.bz2 and /dev/null differ diff --git a/third_party/libosmium/test/t/io/deleted_nodes.osh b/third_party/libosmium/test/t/io/deleted_nodes.osh deleted file mode 100644 index 639e05149..000000000 --- a/third_party/libosmium/test/t/io/deleted_nodes.osh +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/third_party/libosmium/test/t/io/deleted_nodes.osh.pbf b/third_party/libosmium/test/t/io/deleted_nodes.osh.pbf deleted file mode 100644 index 8a94870d1..000000000 Binary files a/third_party/libosmium/test/t/io/deleted_nodes.osh.pbf and /dev/null differ diff --git a/third_party/libosmium/test/t/io/test_bzip2.cpp b/third_party/libosmium/test/t/io/test_bzip2.cpp deleted file mode 100644 index 5cc30b427..000000000 --- a/third_party/libosmium/test/t/io/test_bzip2.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "catch.hpp" -#include "utils.hpp" - -#include -#include -#include - -#include - -TEST_CASE("Bzip2") { - - SECTION("read_compressed_file") { - std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2"); - - int fd = ::open(input_file.c_str(), O_RDONLY); - REQUIRE(fd > 0); - - size_t size = 0; - std::string all; - { - osmium::io::Bzip2Decompressor decomp(fd); - for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) { - size += data.size(); - all += data; - } - } - - REQUIRE(9 == size); - REQUIRE("TESTDATA\n" == all); - } - -} - diff --git a/third_party/libosmium/test/t/io/test_file_formats.cpp b/third_party/libosmium/test/t/io/test_file_formats.cpp deleted file mode 100644 index f0ba0c66f..000000000 --- a/third_party/libosmium/test/t/io/test_file_formats.cpp +++ /dev/null @@ -1,275 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -TEST_CASE("FileFormats") { - - SECTION("default_file_format") { - osmium::io::File f; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("stdin_stdout_empty") { - osmium::io::File f {""}; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("stdin_stdout_dash") { - osmium::io::File f {"-"}; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("stdin_stdout_bz2") { - osmium::io::File f {"-", "osm.bz2"}; - REQUIRE("" == f.filename()); - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_osm") { - osmium::io::File f {"test.osm"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_pbf") { - osmium::io::File f {"test.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_osm_pbf") { - osmium::io::File f {"test.osm.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_opl") { - osmium::io::File f {"test.opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_osm_opl") { - osmium::io::File f {"test.osm.opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_osm_gz") { - osmium::io::File f {"test.osm.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_opl_bz2") { - osmium::io::File f {"test.osm.opl.bz2"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_osc_gz") { - osmium::io::File f {"test.osc.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_opl_gz") { - osmium::io::File f {"test.osh.opl.gz"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("detect_file_format_by_suffix_osh_pbf") { - osmium::io::File f {"test.osh.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osm") { - osmium::io::File f {"test", "osm"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_pbf") { - osmium::io::File f {"test", "pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osm_pbf") { - osmium::io::File f {"test", "osm.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_opl") { - osmium::io::File f {"test", "opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osm_opl") { - osmium::io::File f {"test", "osm.opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osm_gz") { - osmium::io::File f {"test", "osm.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osm_opl_bz2") { - osmium::io::File f {"test", "osm.opl.bz2"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osc_gz") { - osmium::io::File f {"test", "osc.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osh_opl_gz") { - osmium::io::File f {"test", "osh.opl.gz"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("override_file_format_by_suffix_osh_pbf") { - osmium::io::File f {"test", "osh.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("format_options_pbf_history") { - osmium::io::File f {"test", "pbf,history=true"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("format_options_pbf_foo") { - osmium::io::File f {"test.osm", "pbf,foo=bar"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE("bar" == f.get("foo")); - f.check(); - } - - SECTION("format_options_xml_abc_something") { - osmium::io::File f {"test.bla", "xml,abc,some=thing"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE("true" == f.get("abc")); - REQUIRE("thing" == f.get("some")); - REQUIRE(2 == std::distance(f.begin(), f.end())); - f.check(); - } - - SECTION("unknown_format_foo_bar") { - osmium::io::File f {"test.foo.bar"}; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("unknown_format_foo") { - osmium::io::File f {"test", "foo"}; - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("unknown_format_osm_foo") { - osmium::io::File f {"test", "osm.foo"}; - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("unknown_format_bla_equals_foo") { - osmium::io::File f {"test", "bla=foo"}; - REQUIRE_THROWS_AS(f.check(), std::runtime_error); - } - - SECTION("url without format") { - osmium::io::File f {"http://www.example.com/api"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("url without format and filename") { - osmium::io::File f {"http://planet.osm.org/pbf/planet-latest.osm.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); - } - - SECTION("url with format") { - osmium::io::File f {"http://www.example.com/api", "osh"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); - } - -} - diff --git a/third_party/libosmium/test/t/io/test_output_iterator.cpp b/third_party/libosmium/test/t/io/test_output_iterator.cpp deleted file mode 100644 index 7a1f57027..000000000 --- a/third_party/libosmium/test/t/io/test_output_iterator.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "catch.hpp" - -#include -#include -#include - -TEST_CASE("output iterator") { - - SECTION("should be copy constructable") { - osmium::io::Header header; - osmium::io::Writer writer("test.osm", header, osmium::io::overwrite::allow); - osmium::io::OutputIterator out1(writer); - - osmium::io::OutputIterator out2(out1); - } - - SECTION("should be copy assignable") { - osmium::io::Header header; - osmium::io::Writer writer1("test1.osm", header, osmium::io::overwrite::allow); - osmium::io::Writer writer2("test2.osm", header, osmium::io::overwrite::allow); - - osmium::io::OutputIterator out1(writer1); - osmium::io::OutputIterator out2(writer2); - - out2 = out1; - } - - SECTION("should be incrementable") { - osmium::io::Header header; - osmium::io::Writer writer("test.osm", header, osmium::io::overwrite::allow); - osmium::io::OutputIterator out(writer); - - ++out; - } - -} - diff --git a/third_party/libosmium/test/t/io/test_output_utils.cpp b/third_party/libosmium/test/t/io/test_output_utils.cpp deleted file mode 100644 index a76068348..000000000 --- a/third_party/libosmium/test/t/io/test_output_utils.cpp +++ /dev/null @@ -1,153 +0,0 @@ - -#include "catch.hpp" - -#include - -#include - -TEST_CASE("output formatted") { - - std::string out; - - SECTION("small results") { - osmium::io::detail::append_printf_formatted_string(out, "%d", 17); - REQUIRE(out == "17"); - } - - SECTION("several parameters") { - osmium::io::detail::append_printf_formatted_string(out, "%d %s", 17, "foo"); - REQUIRE(out == "17 foo"); - - } - - SECTION("string already containing something") { - out += "foo"; - osmium::io::detail::append_printf_formatted_string(out, " %d", 23); - REQUIRE(out == "foo 23"); - } - - SECTION("large results") { - const char* str = - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; - - osmium::io::detail::append_printf_formatted_string(out, "%s", str); - - REQUIRE(out == str); - } - -} - -TEST_CASE("UTF8 encoding") { - - std::string out; - - SECTION("append to string") { - out += "1234"; - osmium::io::detail::append_utf8_encoded_string(out, "abc"); - REQUIRE(out == "1234abc"); - } - - SECTION("don't encode alphabetic characters") { - const char* s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - osmium::io::detail::append_utf8_encoded_string(out, s); - REQUIRE(out == s); - } - - SECTION("don't encode numeric characters") { - const char* s = "0123456789"; - osmium::io::detail::append_utf8_encoded_string(out, s); - REQUIRE(out == s); - } - - SECTION("don't encode lots of often used characters characters") { - const char* s = ".-;:_#+"; - osmium::io::detail::append_utf8_encoded_string(out, s); - REQUIRE(out == s); - } - - SECTION("encode characters that are special in OPL") { - osmium::io::detail::append_utf8_encoded_string(out, " \n,=@"); - REQUIRE(out == "%20%%0a%%2c%%3d%%40%"); - } - -// workaround for missing support for u8 string literals on Windows -#if !defined(_MSC_VER) - - SECTION("encode multibyte character") { - osmium::io::detail::append_utf8_encoded_string(out, u8"\u30dc_\U0001d11e_\U0001f6eb"); - REQUIRE(out == "%30dc%_%1d11e%_%1f6eb%"); - } - -#endif - -} - -TEST_CASE("html encoding") { - - std::string out; - - SECTION("do not encode normal characters") { - const char* s = "abc123,.-"; - osmium::io::detail::append_xml_encoded_string(out, s); - REQUIRE(out == s); - } - - SECTION("encode special XML characters") { - const char* s = "& \" \' < > \n \r \t"; - osmium::io::detail::append_xml_encoded_string(out, s); - REQUIRE(out == "& " ' < > "); - } - -} - -TEST_CASE("debug encoding") { - - std::string out; - - SECTION("do not encode normal characters") { - const char* s = "abc123,.-"; - osmium::io::detail::append_debug_encoded_string(out, s, "[", "]"); - REQUIRE(out == s); - } - - SECTION("encode some unicode characters") { - const char* s = u8"\n_\u30dc_\U0001d11e_\U0001f6eb"; - osmium::io::detail::append_debug_encoded_string(out, s, "[", "]"); - REQUIRE(out == "[]_[]_[]_[]"); - } - -} - -TEST_CASE("encoding of non-printable characters in the first 127 characters") { - - std::locale cloc("C"); - char s[] = "a\0"; - - for (char c = 1; c < 0x7f; ++c) { - std::string out; - s[0] = c; - - SECTION("utf8 encode") { - osmium::io::detail::append_utf8_encoded_string(out, s); - - if (!std::isprint(c, cloc)) { - REQUIRE(out[0] == '%'); - } - } - - SECTION("debug encode") { - osmium::io::detail::append_debug_encoded_string(out, s, "", ""); - - if (!std::isprint(c, cloc)) { - REQUIRE(out[0] == '<'); - } - } - - } - -} - diff --git a/third_party/libosmium/test/t/io/test_reader.cpp b/third_party/libosmium/test/t/io/test_reader.cpp deleted file mode 100644 index a83af52ab..000000000 --- a/third_party/libosmium/test/t/io/test_reader.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include "catch.hpp" -#include "utils.hpp" - -#include -#include -#include -#include -#include -#include - -struct CountHandler : public osmium::handler::Handler { - - int count = 0; - - void node(osmium::Node&) { - ++count; - } - -}; // class CountHandler - -struct ZeroPositionNodeCountHandler : public osmium::handler::Handler { - - // number of nodes seen at zero position, or visible with undefined - // location. - int count = 0; - int total_count = 0; // total number of nodes seen - const osmium::Location zero = osmium::Location(int32_t(0), int32_t(0)); - - void node(osmium::Node &n) { - // no nodes in the history file have a zero location, and - // no visible nodes should have an undefined location. - if ((n.location() == zero) || - (n.visible() && !n.location())) { - ++count; - } - ++total_count; - } - -}; // class ZeroPositionNodeCountHandler - - -TEST_CASE("Reader") { - - SECTION("reader can be initialized with file") { - osmium::io::File file(with_data_dir("t/io/data.osm")); - osmium::io::Reader reader(file); - osmium::handler::Handler handler; - - osmium::apply(reader, handler); - } - - SECTION("reader can be initialized with string") { - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - osmium::handler::Handler handler; - - osmium::apply(reader, handler); - } - - SECTION("should throw after eof") { - osmium::io::File file(with_data_dir("t/io/data.osm")); - osmium::io::Reader reader(file); - - REQUIRE(!reader.eof()); - - while (osmium::memory::Buffer buffer = reader.read()) { - } - - REQUIRE(reader.eof()); - - REQUIRE_THROWS_AS({ - reader.read(); - }, osmium::io_error); - } - - SECTION("should not hang when apply() is called twice on reader") { - osmium::io::File file(with_data_dir("t/io/data.osm")); - osmium::io::Reader reader(file); - osmium::handler::Handler handler; - - osmium::apply(reader, handler); - REQUIRE_THROWS_AS({ - osmium::apply(reader, handler); - }, osmium::io_error); - } - - SECTION("should work with a buffer with uncompressed data") { - int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm")); - REQUIRE(fd >= 0); - - const size_t buffer_size = 1000; - char buffer[buffer_size]; - auto length = ::read(fd, buffer, buffer_size); - REQUIRE(length > 0); - - osmium::io::File file(buffer, static_cast(length), "osm"); - osmium::io::Reader reader(file); - CountHandler handler; - - REQUIRE(handler.count == 0); - osmium::apply(reader, handler); - REQUIRE(handler.count == 1); - } - - SECTION("should work with a buffer with gzip-compressed data") { - int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.gz")); - REQUIRE(fd >= 0); - - const size_t buffer_size = 1000; - char buffer[buffer_size]; - auto length = ::read(fd, buffer, buffer_size); - REQUIRE(length > 0); - - osmium::io::File file(buffer, static_cast(length), "osm.gz"); - osmium::io::Reader reader(file); - CountHandler handler; - - REQUIRE(handler.count == 0); - osmium::apply(reader, handler); - REQUIRE(handler.count == 1); - } - - SECTION("should work with a buffer with bzip2-compressed data") { - int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.bz2")); - REQUIRE(fd >= 0); - - const size_t buffer_size = 1000; - char buffer[buffer_size]; - auto length = ::read(fd, buffer, buffer_size); - REQUIRE(length > 0); - - osmium::io::File file(buffer, static_cast(length), "osm.bz2"); - osmium::io::Reader reader(file); - CountHandler handler; - - REQUIRE(handler.count == 0); - osmium::apply(reader, handler); - REQUIRE(handler.count == 1); - } - - SECTION("should decode zero node positions in history (XML)") { - osmium::io::Reader reader(with_data_dir("t/io/deleted_nodes.osh"), - osmium::osm_entity_bits::node); - ZeroPositionNodeCountHandler handler; - - REQUIRE(handler.count == 0); - REQUIRE(handler.total_count == 0); - - osmium::apply(reader, handler); - - REQUIRE(handler.count == 0); - REQUIRE(handler.total_count == 2); - } - - SECTION("should decode zero node positions in history (PBF)") { - osmium::io::Reader reader(with_data_dir("t/io/deleted_nodes.osh.pbf"), - osmium::osm_entity_bits::node); - ZeroPositionNodeCountHandler handler; - - REQUIRE(handler.count == 0); - REQUIRE(handler.total_count == 0); - - osmium::apply(reader, handler); - - REQUIRE(handler.count == 0); - REQUIRE(handler.total_count == 2); - } - -} - -TEST_CASE("Reader failure modes") { - - SECTION("should fail with nonexistent file") { - REQUIRE_THROWS({ - osmium::io::Reader reader(with_data_dir("t/io/nonexistent-file.osm")); - }); - } - - SECTION("should fail with nonexistent file (gz)") { - REQUIRE_THROWS({ - osmium::io::Reader reader(with_data_dir("t/io/nonexistent-file.osm.gz")); - }); - } - - SECTION("should fail with nonexistent file (pbf)") { - REQUIRE_THROWS({ - osmium::io::Reader reader(with_data_dir("t/io/nonexistent-file.osm.pbf")); - }); - } - - SECTION("should work when there is an exception in main thread before getting header") { - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - REQUIRE(!reader.eof()); - throw std::runtime_error("foo"); - } catch (...) { - } - - } - - SECTION("should work when there is an exception in main thread while reading") { - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - REQUIRE(!reader.eof()); - auto header = reader.header(); - throw std::runtime_error("foo"); - } catch (...) { - } - - } - -} - diff --git a/third_party/libosmium/test/t/io/test_reader_with_mock_decompression.cpp b/third_party/libosmium/test/t/io/test_reader_with_mock_decompression.cpp deleted file mode 100644 index 566295aff..000000000 --- a/third_party/libosmium/test/t/io/test_reader_with_mock_decompression.cpp +++ /dev/null @@ -1,145 +0,0 @@ - -#include "catch.hpp" -#include "utils.hpp" - -#include - -#include -#include - -// The MockDecompressor behaves like other Decompressor classes, but "invents" -// OSM data in XML format that can be read. Through a parameter to the -// constructor it can be instructed to throw an exception in specific parts -// of its code. This is then used to test the internals of the Reader. - -class MockDecompressor : public osmium::io::Decompressor { - - std::string m_fail_in; - int m_read_count = 0; - -public: - - MockDecompressor(const std::string& fail_in) : - Decompressor(), - m_fail_in(fail_in) { - if (m_fail_in == "constructor") { - throw std::runtime_error("error constructor"); - } - } - - ~MockDecompressor() noexcept final = default; - - void add_node(std::string& s, int i) { - s += "\n"; - } - - std::string read() final { - std::string buffer; - ++m_read_count; - - if (m_read_count == 1) { - if (m_fail_in == "first read") { - throw std::runtime_error("error first read"); - } else { - buffer += "\n\n"; - for (int i = 0; i < 1000; ++i) { - add_node(buffer, i); - } - } - } else if (m_read_count == 2) { - if (m_fail_in == "second read") { - throw std::runtime_error("error second read"); - } else { - for (int i = 1000; i < 2000; ++i) { - add_node(buffer, i); - } - } - } else if (m_read_count == 3) { - buffer += ""; - } - - return buffer; - } - - void close() final { - if (m_fail_in == "close") { - throw std::runtime_error("error close"); - } - } - -}; // class MockDecompressor - -TEST_CASE("Test Reader using MockDecompressor") { - - std::string fail_in; - - osmium::io::CompressionFactory::instance().register_compression(osmium::io::file_compression::gzip, - [](int, osmium::io::fsync) { return nullptr; }, - [&](int) { return new MockDecompressor(fail_in); }, - [](const char*, size_t) { return nullptr; } - ); - - SECTION("fail in constructor") { - fail_in = "constructor"; - - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz")); - REQUIRE(false); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error constructor"); - } - } - - SECTION("fail in first read") { - fail_in = "first read"; - - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz")); - reader.read(); - REQUIRE(false); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error first read"); - } - } - - SECTION("fail in second read") { - fail_in = "second read"; - - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz")); - reader.read(); - reader.read(); - REQUIRE(false); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error second read"); - } - } - - SECTION("fail in close") { - fail_in = "close"; - - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz")); - reader.read(); - reader.read(); - reader.read(); - reader.close(); - REQUIRE(false); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error close"); - } - } - - SECTION("not failing") { - fail_in = "not"; - - osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz")); - reader.read(); - reader.close(); - REQUIRE(true); - } - -} - diff --git a/third_party/libosmium/test/t/io/test_reader_with_mock_parser.cpp b/third_party/libosmium/test/t/io/test_reader_with_mock_parser.cpp deleted file mode 100644 index 7c7dcddba..000000000 --- a/third_party/libosmium/test/t/io/test_reader_with_mock_parser.cpp +++ /dev/null @@ -1,123 +0,0 @@ - -#include "catch.hpp" -#include "utils.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class MockParser : public osmium::io::detail::Parser { - - std::string m_fail_in; - -public: - - MockParser(osmium::io::detail::future_string_queue_type& input_queue, - osmium::io::detail::future_buffer_queue_type& output_queue, - std::promise& header_promise, - osmium::osm_entity_bits::type read_types, - const std::string& fail_in) : - Parser(input_queue, output_queue, header_promise, read_types), - m_fail_in(fail_in) { - } - - osmium::memory::Buffer create_testdata() { - osmium::memory::Buffer buffer(1000); - - { - osmium::builder::NodeBuilder nb(buffer); - nb.add_user("foo"); - } - buffer.commit(); - - return buffer; - } - - void run() final { - osmium::thread::set_thread_name("_osmium_mock_in"); - - if (m_fail_in == "header") { - throw std::runtime_error("error in header"); - } - - set_header_value(osmium::io::Header{}); - - send_to_output_queue(create_testdata()); - - if (m_fail_in == "read") { - throw std::runtime_error("error in read"); - } - } - -}; // class MockParser - -TEST_CASE("Test Reader using MockParser") { - - std::string fail_in; - - osmium::io::detail::ParserFactory::instance().register_parser( - osmium::io::file_format::xml, - [&](osmium::io::detail::future_string_queue_type& input_queue, - osmium::io::detail::future_buffer_queue_type& output_queue, - std::promise& header_promise, - osmium::osm_entity_bits::type read_which_entities) { - return std::unique_ptr(new MockParser(input_queue, output_queue, header_promise, read_which_entities, fail_in)); - }); - - SECTION("no failure") { - fail_in = ""; - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - auto header = reader.header(); - REQUIRE(reader.read()); - REQUIRE(!reader.read()); - REQUIRE(reader.eof()); - reader.close(); - } - - SECTION("throw in header") { - fail_in = "header"; - try { - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - reader.header(); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error in header"); - } - } - - SECTION("throw in read") { - fail_in = "read"; - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - reader.header(); - try { - reader.read(); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error in read"); - } - reader.close(); - } - - SECTION("throw in user code") { - fail_in = ""; - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - reader.header(); - try { - throw std::runtime_error("error in user code"); - } catch (std::runtime_error& e) { - REQUIRE(std::string{e.what()} == "error in user code"); - } - REQUIRE(reader.read()); - REQUIRE(!reader.read()); - REQUIRE(reader.eof()); - reader.close(); - } - -} - diff --git a/third_party/libosmium/test/t/io/test_string_table.cpp b/third_party/libosmium/test/t/io/test_string_table.cpp deleted file mode 100644 index ab977e8bc..000000000 --- a/third_party/libosmium/test/t/io/test_string_table.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("String store") { - osmium::io::detail::StringStore ss(100); - - SECTION("empty") { - REQUIRE(ss.begin() == ss.end()); - } - - SECTION("add zero-length string") { - const char* s1 = ss.add(""); - REQUIRE(std::string(s1) == ""); - - auto it = ss.begin(); - REQUIRE(s1 == *it); - REQUIRE(std::string(*it) == ""); - REQUIRE(++it == ss.end()); - } - - SECTION("add strings") { - const char* s1 = ss.add("foo"); - const char* s2 = ss.add("bar"); - REQUIRE(s1 != s2); - REQUIRE(std::string(s1) == "foo"); - REQUIRE(std::string(s2) == "bar"); - - auto it = ss.begin(); - REQUIRE(s1 == *it++); - REQUIRE(s2 == *it++); - REQUIRE(it == ss.end()); - } - - SECTION("add zero-length string and longer strings") { - ss.add(""); - ss.add("xxx"); - ss.add("yyyyy"); - - auto it = ss.begin(); - REQUIRE(std::string(*it++) == ""); - REQUIRE(std::string(*it++) == "xxx"); - REQUIRE(std::string(*it++) == "yyyyy"); - REQUIRE(it == ss.end()); - } - - SECTION("add many strings") { - for (const char* teststring : {"a", "abc", "abcd", "abcde"}) { - int i = 0; - for (; i < 100; ++i) { - ss.add(teststring); - } - - for (const char* s : ss) { - REQUIRE(std::string(s) == teststring); - --i; - } - - REQUIRE(i == 0); - ss.clear(); - } - } - -} - -TEST_CASE("String table") { - osmium::io::detail::StringTable st; - - SECTION("empty") { - REQUIRE(st.size() == 1); - REQUIRE(std::next(st.begin()) == st.end()); - } - - SECTION("add strings") { - REQUIRE(st.add("foo") == 1); - REQUIRE(st.add("bar") == 2); - REQUIRE(st.add("bar") == 2); - REQUIRE(st.add("baz") == 3); - REQUIRE(st.add("foo") == 1); - REQUIRE(st.size() == 4); - - auto it = st.begin(); - REQUIRE(std::string("") == *it++); - REQUIRE(std::string("foo") == *it++); - REQUIRE(std::string("bar") == *it++); - REQUIRE(std::string("baz") == *it++); - REQUIRE(it == st.end()); - - st.clear(); - REQUIRE(st.size() == 1); - } - -} - diff --git a/third_party/libosmium/test/t/io/test_writer.cpp b/third_party/libosmium/test/t/io/test_writer.cpp deleted file mode 100644 index 45593cf60..000000000 --- a/third_party/libosmium/test/t/io/test_writer.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "catch.hpp" -#include "utils.hpp" - -#include - -#include -#include -#include -#include -#include - -TEST_CASE("Writer") { - - osmium::io::Header header; - header.set("generator", "test_writer.cpp"); - - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(buffer); - REQUIRE(buffer.committed() > 0); - auto num = std::distance(buffer.cbegin(), buffer.cend()); - REQUIRE(num > 0); - REQUIRE(buffer.cbegin()->id() == 1); - - std::string filename; - - SECTION("Empty writes") { - - SECTION("Empty buffer") { - filename = "test-writer-out-empty-buffer.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - osmium::memory::Buffer empty_buffer(1024); - writer(std::move(empty_buffer)); - writer.close(); - } - - SECTION("Invalid buffer") { - filename = "test-writer-out-invalid-buffer.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - osmium::memory::Buffer invalid_buffer; - writer(std::move(invalid_buffer)); - writer.close(); - } - - osmium::io::Reader reader_check(filename); - osmium::memory::Buffer buffer_check = reader_check.read(); - REQUIRE(!buffer_check); - } - - SECTION("Successfull writes") { - - SECTION("Writer buffer") { - filename = "test-writer-out-buffer.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - - REQUIRE_THROWS_AS({ - writer(osmium::memory::Buffer{}); - }, osmium::io_error); - } - - SECTION("Writer item") { - filename = "test-writer-out-item.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - for (const auto& item : buffer) { - writer(item); - } - writer.close(); - } - - SECTION("Writer output iterator") { - filename = "test-writer-out-iterator.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - auto it = osmium::io::make_output_iterator(writer); - std::copy(buffer.cbegin(), buffer.cend(), it); - writer.close(); - } - - osmium::io::Reader reader_check(filename); - osmium::memory::Buffer buffer_check = reader_check.read(); - REQUIRE(buffer_check); - REQUIRE(buffer_check.committed() > 0); - REQUIRE(std::distance(buffer_check.cbegin(), buffer_check.cend()) == num); - REQUIRE(buffer_check.cbegin()->id() == 1); - - } - - SECTION("Interrupted write") { - - int error = 0; - try { - - SECTION("fail after open") { - filename = "test-writer-out-fail1.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - throw 1; - } - - SECTION("fail after write") { - filename = "test-writer-out-fail2.osm"; - osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - throw 2; - } - - } catch (int e) { - error = e; - } - - REQUIRE(error > 0); - - } - -} - - diff --git a/third_party/libosmium/test/t/io/test_writer_with_mock_compression.cpp b/third_party/libosmium/test/t/io/test_writer_with_mock_compression.cpp deleted file mode 100644 index c2d3bbd49..000000000 --- a/third_party/libosmium/test/t/io/test_writer_with_mock_compression.cpp +++ /dev/null @@ -1,99 +0,0 @@ - -#include "catch.hpp" -#include "utils.hpp" - -#include -#include - -#include -#include -#include - -class MockCompressor : public osmium::io::Compressor { - - std::string m_fail_in; - -public: - - MockCompressor(const std::string& fail_in) : - Compressor(osmium::io::fsync::no), - m_fail_in(fail_in) { - if (m_fail_in == "constructor") { - throw std::logic_error("constructor"); - } - } - - ~MockCompressor() noexcept final = default; - - void write(const std::string&) final { - if (m_fail_in == "write") { - throw std::logic_error("write"); - } - } - - void close() final { - if (m_fail_in == "close") { - throw std::logic_error("close"); - } - } - -}; // class MockCompressor - -TEST_CASE("Write with mock compressor") { - - std::string fail_in; - - osmium::io::CompressionFactory::instance().register_compression(osmium::io::file_compression::gzip, - [&](int, osmium::io::fsync) { return new MockCompressor(fail_in); }, - [](int) { return nullptr; }, - [](const char*, size_t) { return nullptr; } - ); - - osmium::io::Header header; - header.set("generator", "test_writer_with_mock_compression.cpp"); - - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(buffer); - REQUIRE(buffer.committed() > 0); - auto num = std::distance(buffer.cbegin(), buffer.cend()); - REQUIRE(num > 0); - - SECTION("fail on construction") { - - fail_in = "constructor"; - - REQUIRE_THROWS_AS({ - osmium::io::Writer writer("test-writer-mock-fail-on-construction.osm.gz", header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - }, std::logic_error); - - } - - SECTION("fail on write") { - - fail_in = "write"; - - REQUIRE_THROWS_AS({ - osmium::io::Writer writer("test-writer-mock-fail-on-write.osm.gz", header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - }, std::logic_error); - - } - - SECTION("fail on close") { - - fail_in = "close"; - - REQUIRE_THROWS_AS({ - osmium::io::Writer writer("test-writer-mock-fail-on-close.osm.gz", header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - }, std::logic_error); - - } - -} - diff --git a/third_party/libosmium/test/t/io/test_writer_with_mock_encoder.cpp b/third_party/libosmium/test/t/io/test_writer_with_mock_encoder.cpp deleted file mode 100644 index a43d59183..000000000 --- a/third_party/libosmium/test/t/io/test_writer_with_mock_encoder.cpp +++ /dev/null @@ -1,105 +0,0 @@ - -#include "catch.hpp" -#include "utils.hpp" - -#include -#include - -#include -#include -#include -#include -#include - -class MockOutputFormat : public osmium::io::detail::OutputFormat { - - std::string m_fail_in; - -public: - - MockOutputFormat(const osmium::io::File&, osmium::io::detail::future_string_queue_type& output_queue, const std::string& fail_in) : - OutputFormat(output_queue), - m_fail_in(fail_in) { - } - - void write_header(const osmium::io::Header&) final { - if (m_fail_in == "header") { - throw std::logic_error("header"); - } - send_to_output_queue(std::string{"header"}); - } - - void write_buffer(osmium::memory::Buffer&&) final { - if (m_fail_in == "write") { - throw std::logic_error("write"); - } - send_to_output_queue(std::string{"write"}); - } - - void write_end() final { - if (m_fail_in == "write_end") { - throw std::logic_error("write_end"); - } - send_to_output_queue(std::string{"end"}); - } - -}; // class MockOutputFormat - -TEST_CASE("Test Writer with MockOutputFormat") { - - std::string fail_in; - - osmium::io::detail::OutputFormatFactory::instance().register_output_format( - osmium::io::file_format::xml, - [&](const osmium::io::File& file, osmium::io::detail::future_string_queue_type& output_queue) { - return new MockOutputFormat(file, output_queue, fail_in); - }); - - osmium::io::Header header; - header.set("generator", "test_writer_with_mock_encoder.cpp"); - - osmium::io::Reader reader(with_data_dir("t/io/data.osm")); - osmium::memory::Buffer buffer = reader.read(); - REQUIRE(buffer); - REQUIRE(buffer.committed() > 0); - auto num = std::distance(buffer.cbegin(), buffer.cend()); - REQUIRE(num > 0); - - SECTION("error in header") { - - fail_in = "header"; - - REQUIRE_THROWS_AS({ - osmium::io::Writer writer("test-writer-mock-fail-on-construction.osm", header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - }, std::logic_error); - - } - - SECTION("error in write") { - - fail_in = "write"; - - REQUIRE_THROWS_AS({ - osmium::io::Writer writer("test-writer-mock-fail-on-construction.osm", header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - }, std::logic_error); - - } - - SECTION("error in write_end") { - - fail_in = "write_end"; - - REQUIRE_THROWS_AS({ - osmium::io::Writer writer("test-writer-mock-fail-on-construction.osm", header, osmium::io::overwrite::allow); - writer(std::move(buffer)); - writer.close(); - }, std::logic_error); - - } - -} - diff --git a/third_party/libosmium/test/t/tags/test_filter.cpp b/third_party/libosmium/test/t/tags/test_filter.cpp deleted file mode 100644 index eefa5b076..000000000 --- a/third_party/libosmium/test/t/tags/test_filter.cpp +++ /dev/null @@ -1,216 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -template -void check_filter(const osmium::TagList& tag_list, const TFilter filter, const std::vector& reference) { - REQUIRE(tag_list.size() == reference.size()); - auto t_it = tag_list.begin(); - for (auto it = reference.begin(); it != reference.end(); ++t_it, ++it) { - REQUIRE(filter(*t_it) == *it); - } - - typename TFilter::iterator fi_begin(filter, tag_list.begin(), tag_list.end()); - typename TFilter::iterator fi_end(filter, tag_list.end(), tag_list.end()); - - REQUIRE(std::distance(fi_begin, fi_end) == std::count(reference.begin(), reference.end(), true)); -} - -TEST_CASE("Filter") { - - SECTION("KeyFilter_matches_some_tags") { - osmium::tags::KeyFilter filter(false); - filter.add(true, "highway").add(true, "railway"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, // match - { "name", "Main Street" }, // no match - { "source", "GPS" } // no match - }); - - std::vector results = { true, false, false }; - - check_filter(tag_list, filter, results); - } - - SECTION("KeyFilter_iterator_filters_tags") { - osmium::tags::KeyFilter filter(false); - filter.add(true, "highway").add(true, "source"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, // match - { "name", "Main Street" }, // no match - { "source", "GPS" } // no match - }); - - osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end()); - const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end()); - - REQUIRE(2 == std::distance(it, end)); - - REQUIRE(it != end); - REQUIRE(std::string("highway") == it->key()); - REQUIRE(std::string("primary") == it->value()); - ++it; - REQUIRE(std::string("source") == it->key()); - REQUIRE(std::string("GPS") == it->value()); - REQUIRE(++it == end); - } - - SECTION("KeyValueFilter_matches_some_tags") { - osmium::tags::KeyValueFilter filter(false); - - filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "railway", "tram" }, - { "source", "GPS" } - }); - - std::vector results = {true, true, false}; - - check_filter(tag_list, filter, results); - } - - SECTION("KeyValueFilter_ordering_matters") { - osmium::tags::KeyValueFilter filter1(false); - filter1.add(true, "highway").add(false, "highway", "road"); - - osmium::tags::KeyValueFilter filter2(false); - filter2.add(false, "highway", "road").add(true, "highway"); - - osmium::memory::Buffer buffer(10240); - - const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { - { "highway", "road" }, - { "name", "Main Street" } - }); - - const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); - - check_filter(tag_list1, filter1, {true, false}); - check_filter(tag_list1, filter2, {false, false}); - check_filter(tag_list2, filter2, {true, false}); - } - - SECTION("KeyValueFilter_matches_against_taglist_with_any") { - osmium::tags::KeyValueFilter filter(false); - - filter.add(true, "highway", "primary").add(true, "name"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "railway", "tram" }, - { "source", "GPS" } - }); - - REQUIRE( osmium::tags::match_any_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); - } - - SECTION("KeyValueFilter_matches_against_taglist_with_all") { - osmium::tags::KeyValueFilter filter(false); - - filter.add(true, "highway", "primary").add(true, "name"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); - - REQUIRE( osmium::tags::match_any_of(tag_list, filter)); - REQUIRE( osmium::tags::match_all_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); - } - - SECTION("KeyValueFilter_matches_against_taglist_with_none") { - osmium::tags::KeyValueFilter filter(false); - - filter.add(true, "highway", "road").add(true, "source"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); - - REQUIRE(!osmium::tags::match_any_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); - REQUIRE( osmium::tags::match_none_of(tag_list, filter)); - } - - SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") { - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "railway", "tram" }, - { "source", "GPS" } - }); - - REQUIRE(osmium::tags::match_any_of(tag_list, - osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name"))); - } - - SECTION("RegexFilter_matches_some_tags") { - osmium::tags::RegexFilter filter(false); - filter.add(true, "highway", std::regex(".*_link")); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { - { "highway", "primary_link" }, - { "source", "GPS" } - }); - const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "source", "GPS" } - }); - - check_filter(tag_list1, filter, {true, false}); - check_filter(tag_list2, filter, {false, false}); - } - - SECTION("RegexFilter_matches_some_tags_with_lvalue_regex") { - osmium::tags::RegexFilter filter(false); - std::regex r(".*straße"); - filter.add(true, "name", r); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Hauptstraße" } - }); - - check_filter(tag_list, filter, {false, true}); - } - - SECTION("KeyPrefixFilter_matches_some_tags") { - osmium::tags::KeyPrefixFilter filter(false); - filter.add(true, "name:"); - - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name:de", "Hauptstraße" } - }); - - check_filter(tag_list, filter, {false, true}); - } - -} diff --git a/third_party/libosmium/test/t/tags/test_operators.cpp b/third_party/libosmium/test/t/tags/test_operators.cpp deleted file mode 100644 index 33a53c2a2..000000000 --- a/third_party/libosmium/test/t/tags/test_operators.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "catch.hpp" - -#include - -#include -#include -#include - -TEST_CASE("Operators") { - - SECTION("Equal") { - osmium::memory::Buffer buffer1(10240); - { - osmium::builder::TagListBuilder tl_builder(buffer1); - tl_builder.add_tag("highway", "primary"); - tl_builder.add_tag("name", "Main Street"); - tl_builder.add_tag("source", "GPS"); - } - buffer1.commit(); - - osmium::memory::Buffer buffer2(10240); - { - osmium::builder::TagListBuilder tl_builder(buffer2); - tl_builder.add_tag("highway", "primary"); - } - buffer2.commit(); - - const osmium::TagList& tl1 = buffer1.get(0); - const osmium::TagList& tl2 = buffer2.get(0); - - auto tagit1 = tl1.begin(); - auto tagit2 = tl2.begin(); - REQUIRE(*tagit1 == *tagit2); - ++tagit1; - REQUIRE(!(*tagit1 == *tagit2)); - } - - SECTION("Order") { - osmium::memory::Buffer buffer(10240); - { - osmium::builder::TagListBuilder tl_builder(buffer); - tl_builder.add_tag("highway", "residential"); - tl_builder.add_tag("highway", "primary"); - tl_builder.add_tag("name", "Main Street"); - tl_builder.add_tag("amenity", "post_box"); - } - buffer.commit(); - - const osmium::TagList& tl = buffer.get(0); - const osmium::Tag& t1 = *(tl.begin()); - const osmium::Tag& t2 = *(std::next(tl.begin(), 1)); - const osmium::Tag& t3 = *(std::next(tl.begin(), 2)); - const osmium::Tag& t4 = *(std::next(tl.begin(), 3)); - - REQUIRE(t2 < t1); - REQUIRE(t1 < t3); - REQUIRE(t2 < t3); - REQUIRE(t4 < t1); - } - -} diff --git a/third_party/libosmium/test/t/tags/test_tag_list.cpp b/third_party/libosmium/test/t/tags/test_tag_list.cpp deleted file mode 100644 index 295f51af8..000000000 --- a/third_party/libosmium/test/t/tags/test_tag_list.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "catch.hpp" - -#include -#include -#include - -TEST_CASE("create tag list") { - osmium::memory::Buffer buffer(10240); - - SECTION("with TagListBuilder from char*") { - { - osmium::builder::TagListBuilder builder(buffer); - builder.add_tag("highway", "primary"); - builder.add_tag("name", "Main Street"); - } - buffer.commit(); - } - - SECTION("with TagListBuilder from char* with length") { - { - osmium::builder::TagListBuilder builder(buffer); - builder.add_tag("highway", strlen("highway"), "primary", strlen("primary")); - builder.add_tag("nameXX", 4, "Main Street", 11); - } - buffer.commit(); - } - - SECTION("with TagListBuilder from std::string") { - { - osmium::builder::TagListBuilder builder(buffer); - builder.add_tag(std::string("highway"), std::string("primary")); - const std::string source = "name"; - std::string gps = "Main Street"; - builder.add_tag(source, gps); - } - buffer.commit(); - } - - SECTION("with build_tag_list from initializer list") { - osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); - } - - SECTION("with build_tag_list_from_map") { - osmium::builder::build_tag_list_from_map(buffer, std::map({ - { "highway", "primary" }, - { "name", "Main Street" } - })); - } - - SECTION("with build_tag_list_from_func") { - osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { - tlb.add_tag("highway", "primary"); - tlb.add_tag("name", "Main Street"); - }); - } - - const osmium::TagList& tl = *buffer.begin(); - REQUIRE(osmium::item_type::tag_list == tl.type()); - REQUIRE(2 == tl.size()); - - auto it = tl.begin(); - REQUIRE(std::string("highway") == it->key()); - REQUIRE(std::string("primary") == it->value()); - ++it; - REQUIRE(std::string("name") == it->key()); - REQUIRE(std::string("Main Street") == it->value()); - ++it; - REQUIRE(it == tl.end()); - - REQUIRE(std::string("primary") == tl.get_value_by_key("highway")); - REQUIRE(nullptr == tl.get_value_by_key("foo")); - REQUIRE(std::string("default") == tl.get_value_by_key("foo", "default")); - - REQUIRE(std::string("Main Street") == tl["name"]); -} - -TEST_CASE("empty keys and values are okay") { - osmium::memory::Buffer buffer(10240); - - const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { - { "empty value", "" }, - { "", "empty key" } - }); - - REQUIRE(osmium::item_type::tag_list == tl.type()); - REQUIRE(2 == tl.size()); - - auto it = tl.begin(); - REQUIRE(std::string("empty value") == it->key()); - REQUIRE(std::string("") == it->value()); - ++it; - REQUIRE(std::string("") == it->key()); - REQUIRE(std::string("empty key") == it->value()); - ++it; - REQUIRE(it == tl.end()); - - REQUIRE(std::string("") == tl.get_value_by_key("empty value")); - REQUIRE(std::string("empty key") == tl.get_value_by_key("")); -} - -TEST_CASE("tag key or value is too long") { - osmium::memory::Buffer buffer(10240); - osmium::builder::TagListBuilder builder(buffer); - - const char kv[2000] = ""; - builder.add_tag(kv, 1, kv, 1000); - REQUIRE_THROWS(builder.add_tag(kv, 1500, kv, 1)); - REQUIRE_THROWS(builder.add_tag(kv, 1, kv, 1500)); -} - diff --git a/third_party/libosmium/test/t/thread/test_pool.cpp b/third_party/libosmium/test/t/thread/test_pool.cpp deleted file mode 100644 index c1047db49..000000000 --- a/third_party/libosmium/test/t/thread/test_pool.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "catch.hpp" - -#include -#include -#include - -#include -#include - -struct test_job_with_result { - int operator()() const { - return 42; - } -}; - -struct test_job_throw { - OSMIUM_NORETURN void operator()() const { - throw std::runtime_error("exception in pool thread"); - } -}; - -TEST_CASE("number of threads in pool") { - - // hardcoded setting - REQUIRE(osmium::thread::detail::get_pool_size( 1, 0, 2) == 1); - REQUIRE(osmium::thread::detail::get_pool_size( 4, 0, 2) == 4); - REQUIRE(osmium::thread::detail::get_pool_size( 4, 0, 4) == 4); - REQUIRE(osmium::thread::detail::get_pool_size(16, 0, 4) == 16); - REQUIRE(osmium::thread::detail::get_pool_size(16, 0, 16) == 16); - REQUIRE(osmium::thread::detail::get_pool_size( 8, 4, 2) == 8); - REQUIRE(osmium::thread::detail::get_pool_size( 8, 16, 2) == 8); - REQUIRE(osmium::thread::detail::get_pool_size(-2, 16, 2) == 1); - REQUIRE(osmium::thread::detail::get_pool_size(-2, 16, 8) == 6); - - // user decides through OSMIUM_POOL_THREADS env variable - REQUIRE(osmium::thread::detail::get_pool_size( 0, 0, 2) == 1); - REQUIRE(osmium::thread::detail::get_pool_size( 0, -2, 4) == 2); - REQUIRE(osmium::thread::detail::get_pool_size( 0, -1, 8) == 7); - REQUIRE(osmium::thread::detail::get_pool_size( 0, 0, 16) == 14); - REQUIRE(osmium::thread::detail::get_pool_size( 0, 1, 16) == 1); - REQUIRE(osmium::thread::detail::get_pool_size( 0, 2, 16) == 2); - REQUIRE(osmium::thread::detail::get_pool_size( 0, 4, 16) == 4); - REQUIRE(osmium::thread::detail::get_pool_size( 0, 8, 16) == 8); - - // outliers - REQUIRE(osmium::thread::detail::get_pool_size(-100, 0, 16) == 1); - REQUIRE(osmium::thread::detail::get_pool_size(1000, 0, 16) == 256); - -} - -TEST_CASE("thread") { - - auto& pool = osmium::thread::Pool::instance(); - - SECTION("can get access to thread pool") { - REQUIRE(pool.queue_empty()); - } - - SECTION("can send job to thread pool") { - auto future = pool.submit(test_job_with_result {}); - - REQUIRE(future.get() == 42); - } - - SECTION("can throw from job in thread pool") { - auto future = pool.submit(test_job_throw {}); - - REQUIRE_THROWS_AS(future.get(), std::runtime_error); - } - -} - diff --git a/third_party/libosmium/test/t/util/test_cast_with_assert.cpp b/third_party/libosmium/test/t/util/test_cast_with_assert.cpp deleted file mode 100644 index 0231f30e1..000000000 --- a/third_party/libosmium/test/t/util/test_cast_with_assert.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "catch.hpp" - -// Define assert() to throw this error. This enables the tests to check that -// the assert() fails. -struct assert_error : public std::runtime_error { - assert_error(const char* what_arg) : std::runtime_error(what_arg) { - } -}; -#define assert(x) if (!(x)) { throw(assert_error(#x)); } - -#include - -TEST_CASE("static_cast_with_assert") { - - SECTION("same types is always okay") { - int f = 10; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("casting to larger type is always okay") { - int16_t f = 10; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - - SECTION("cast int32_t -> int_16t should not trigger assert for small int") { - int32_t f = 100; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("cast int32_t -> int_16t should trigger assert for large int") { - int32_t f = 100000; - REQUIRE_THROWS_AS(osmium::static_cast_with_assert(f), assert_error); - } - - - SECTION("cast int16_t -> uint16_t should not trigger assert for zero") { - int16_t f = 0; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("cast int16_t -> uint16_t should not trigger assert for positive int") { - int16_t f = 1; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("cast int16_t -> uint16_t should trigger assert for negative int") { - int16_t f = -1; - REQUIRE_THROWS_AS(osmium::static_cast_with_assert(f), assert_error); - } - - - SECTION("cast uint32_t -> uint_16t should not trigger assert for zero") { - uint32_t f = 0; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("cast uint32_t -> uint_16t should not trigger assert for small int") { - uint32_t f = 100; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("cast int32_t -> int_16t should trigger assert for large int") { - uint32_t f = 100000; - REQUIRE_THROWS_AS(osmium::static_cast_with_assert(f), assert_error); - } - - - SECTION("cast uint16_t -> int16_t should not trigger assert for small int") { - uint16_t f = 1; - auto t = osmium::static_cast_with_assert(f); - REQUIRE(t == f); - } - - SECTION("cast uint16_t -> int16_t should trigger assert for large int") { - uint16_t f = 65000; - REQUIRE_THROWS_AS(osmium::static_cast_with_assert(f), assert_error); - } - - -} - diff --git a/third_party/libosmium/test/t/util/test_delta.cpp b/third_party/libosmium/test/t/util/test_delta.cpp deleted file mode 100644 index 667c9b443..000000000 --- a/third_party/libosmium/test/t/util/test_delta.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -TEST_CASE("delta encode int") { - - osmium::util::DeltaEncode x; - - SECTION("int") { - REQUIRE(x.update(17) == 17); - REQUIRE(x.update(10) == -7); - REQUIRE(x.update(-10) == -20); - } - -} - -TEST_CASE("delta decode int") { - - osmium::util::DeltaDecode x; - - SECTION("int") { - REQUIRE(x.update(17) == 17); - REQUIRE(x.update(10) == 27); - REQUIRE(x.update(-40) == -13); - } - -} - -TEST_CASE("delta encode unsigned int") { - - osmium::util::DeltaEncode x; - - SECTION("int") { - REQUIRE(x.update(17) == 17); - REQUIRE(x.update(10) == -7); - REQUIRE(x.update(0) == -10); - } - -} - -TEST_CASE("delta decode unsigned int") { - - osmium::util::DeltaDecode x; - - SECTION("int") { - REQUIRE(x.update(17) == 17); - REQUIRE(x.update(10) == 27); - REQUIRE(x.update(-15) == 12); - } - -} - -TEST_CASE("delta encode and decode") { - - std::vector a = { 5, -9, 22, 13, 0, 23 }; - - osmium::util::DeltaEncode de; - std::vector b; - for (int x : a) { - b.push_back(de.update(x)); - } - - osmium::util::DeltaDecode dd; - std::vector c; - for (int x : b) { - c.push_back(dd.update(x)); - } - -} - -TEST_CASE("delta encode iterator") { - std::vector data = { 4, 5, 13, 22, 12 }; - - auto l = [](std::vector::const_iterator it) -> int { - return *it; - }; - - typedef osmium::util::DeltaEncodeIterator::const_iterator, decltype(l), int> it_type; - it_type it(data.begin(), data.end(), l); - it_type end(data.end(), data.end(), l); - - REQUIRE(*it == 4); - ++it; - REQUIRE(*it++ == 1); - REQUIRE(*it == 8); - ++it; - REQUIRE(*it++ == 9); - REQUIRE(*it == -10); - ++it; - REQUIRE(it == end); -} - diff --git a/third_party/libosmium/test/t/util/test_double.cpp b/third_party/libosmium/test/t/util/test_double.cpp deleted file mode 100644 index 6cc87a03a..000000000 --- a/third_party/libosmium/test/t/util/test_double.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("Double") { - - SECTION("double2string") { - std::string s1; - osmium::util::double2string(s1, 1.123, 7); - REQUIRE(s1 == "1.123"); - - std::string s2; - osmium::util::double2string(s2, 1.000, 7); - REQUIRE(s2 == "1"); - - std::string s3; - osmium::util::double2string(s3, 0.0, 7); - REQUIRE(s3 == "0"); - - std::string s4; - osmium::util::double2string(s4, 0.020, 7); - REQUIRE(s4 == "0.02"); - - std::string s5; - osmium::util::double2string(s5, -0.020, 7); - REQUIRE(s5 == "-0.02"); - - std::string s6; - osmium::util::double2string(s6, -0.0, 7); - REQUIRE(s6 == "-0"); - } -} - diff --git a/third_party/libosmium/test/t/util/test_file.cpp b/third_party/libosmium/test/t/util/test_file.cpp deleted file mode 100644 index 475f28596..000000000 --- a/third_party/libosmium/test/t/util/test_file.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "catch.hpp" - -#include - -#ifdef _WIN32 -#include -// https://msdn.microsoft.com/en-us/library/ksazx244.aspx -// https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx -class DoNothingInvalidParameterHandler { - - static void invalid_parameter_handler( - const wchar_t* expression, - const wchar_t* function, - const wchar_t* file, - unsigned int line, - uintptr_t pReserved - ) { - // do nothing - } - - _invalid_parameter_handler old_handler; - -public: - - DoNothingInvalidParameterHandler() : - old_handler(_set_invalid_parameter_handler(invalid_parameter_handler)) { - _CrtSetReportMode(_CRT_ASSERT, 0); - } - - ~DoNothingInvalidParameterHandler() { - _set_invalid_parameter_handler(old_handler); - } - -}; // class InvalidParameterHandler -#endif - - -TEST_CASE("file_size") { - -#ifdef _WIN32 - DoNothingInvalidParameterHandler handler; -#endif - - SECTION("illegal fd should throw") { - REQUIRE_THROWS_AS(osmium::util::file_size(-1), std::system_error); - } - - SECTION("unused fd should throw") { - // its unlikely that fd 1000 is open... - REQUIRE_THROWS_AS(osmium::util::file_size(1000), std::system_error); - } - -} - -TEST_CASE("resize_file") { - -#ifdef _WIN32 - DoNothingInvalidParameterHandler handler; -#endif - - SECTION("illegal fd should throw") { - REQUIRE_THROWS_AS(osmium::util::resize_file(-1, 10), std::system_error); - } - - SECTION("unused fd should throw") { - // its unlikely that fd 1000 is open... - REQUIRE_THROWS_AS(osmium::util::resize_file(1000, 10), std::system_error); - } - -} - diff --git a/third_party/libosmium/test/t/util/test_memory_mapping.cpp b/third_party/libosmium/test/t/util/test_memory_mapping.cpp deleted file mode 100644 index 29893f7c7..000000000 --- a/third_party/libosmium/test/t/util/test_memory_mapping.cpp +++ /dev/null @@ -1,419 +0,0 @@ -#include "catch.hpp" - -#include -#include - -#include -#include - -#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32)) -#include "win_mkstemp.hpp" -#endif - -static const size_t huge = std::numeric_limits::max(); - -TEST_CASE("anonymous mapping") { - - SECTION("simple memory mapping should work") { - osmium::util::MemoryMapping mapping(1000, osmium::util::MemoryMapping::mapping_mode::write_private); - REQUIRE(mapping.get_addr() != nullptr); - - REQUIRE(mapping.size() >= 1000); - - volatile int* addr = mapping.get_addr(); - - REQUIRE(mapping.writable()); - - *addr = 42; - REQUIRE(*addr == 42); - - REQUIRE(!!mapping); - mapping.unmap(); - REQUIRE(!mapping); - mapping.unmap(); // second unmap is okay - } - - SECTION("memory mapping of zero length should work") { - osmium::util::MemoryMapping mapping(0, osmium::util::MemoryMapping::mapping_mode::write_private); - REQUIRE(mapping.get_addr() != nullptr); - - REQUIRE(mapping.size() == osmium::util::get_pagesize()); - - REQUIRE(!!mapping); - mapping.unmap(); - REQUIRE(!mapping); - } - - SECTION("moving a memory mapping should work") { - osmium::util::MemoryMapping mapping1(1000, osmium::util::MemoryMapping::mapping_mode::write_private); - int* addr1 = mapping1.get_addr(); - *addr1 = 42; - - REQUIRE(!!mapping1); - osmium::util::MemoryMapping mapping2(std::move(mapping1)); - REQUIRE(!!mapping2); - REQUIRE(!mapping1); - mapping1.unmap(); - - int* addr2 = mapping2.get_addr(); - REQUIRE(*addr2 == 42); - - mapping2.unmap(); - REQUIRE(!mapping2); - } - - SECTION("move assignment should work") { - osmium::util::MemoryMapping mapping1(1000, osmium::util::MemoryMapping::mapping_mode::write_private); - osmium::util::MemoryMapping mapping2(1000, osmium::util::MemoryMapping::mapping_mode::write_private); - - REQUIRE(!!mapping1); - REQUIRE(!!mapping2); - - int* addr1 = mapping1.get_addr(); - *addr1 = 42; - - mapping2 = std::move(mapping1); - REQUIRE(!!mapping2); - REQUIRE(!mapping1); - - int* addr2 = mapping2.get_addr(); - REQUIRE(*addr2 == 42); - - mapping2.unmap(); - REQUIRE(!mapping2); - } - -#ifdef __linux__ - SECTION("remapping to larger size should work") { - osmium::util::MemoryMapping mapping(1000, osmium::util::MemoryMapping::mapping_mode::write_private); - REQUIRE(mapping.size() >= 1000); - - size_t size1 = mapping.size(); - - int* addr1 = mapping.get_addr(); - *addr1 = 42; - - mapping.resize(8000); - REQUIRE(mapping.size() > size1); - - int* addr2 = mapping.get_addr(); - REQUIRE(*addr2 == 42); - } - - SECTION("remapping to smaller size should work") { - osmium::util::MemoryMapping mapping(8000, osmium::util::MemoryMapping::mapping_mode::write_private); - REQUIRE(mapping.size() >= 1000); - - size_t size1 = mapping.size(); - - int* addr1 = mapping.get_addr(); - *addr1 = 42; - - mapping.resize(500); - REQUIRE(mapping.size() < size1); - - int* addr2 = mapping.get_addr(); - REQUIRE(*addr2 == 42); - } -#endif - -} - -TEST_CASE("file-based mapping") { - - SECTION("writing to a mapped file should work") { - char filename[] = "test_mmap_write_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - - osmium::util::resize_file(fd, 100); - - { - osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_shared, fd); - REQUIRE(mapping.writable()); - - REQUIRE(!!mapping); - REQUIRE(mapping.size() >= 100); - - *mapping.get_addr() = 1234; - - mapping.unmap(); - } - - REQUIRE(osmium::util::file_size(fd) == 100); - - { - osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::readonly, fd); - REQUIRE(!mapping.writable()); - - REQUIRE(!!mapping); - REQUIRE(mapping.size() >= 100); - REQUIRE(*mapping.get_addr() == 1234); - - mapping.unmap(); - } - - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); - } - - SECTION("writing to a privately mapped file should work") { - char filename[] = "test_mmap_write_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - - osmium::util::resize_file(fd, 100); - - { - osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_private, fd); - REQUIRE(mapping.writable()); - - REQUIRE(!!mapping); - REQUIRE(mapping.size() >= 100); - - *mapping.get_addr() = 1234; - - mapping.unmap(); - } - - REQUIRE(osmium::util::file_size(fd) == 100); - - { - osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::readonly, fd); - REQUIRE(!mapping.writable()); - - REQUIRE(!!mapping); - REQUIRE(mapping.size() >= 100); - REQUIRE(*mapping.get_addr() == 0); // should not see the value set above - - mapping.unmap(); - } - - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); - } - - SECTION("remapping to larger size should work") { - char filename[] = "test_mmap_grow_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - - osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_shared, fd); - REQUIRE(mapping.size() >= 100); - size_t size1 = mapping.size(); - - int* addr1 = mapping.get_addr(); - *addr1 = 42; - - mapping.resize(8000); - REQUIRE(mapping.size() >= 8000); - REQUIRE(mapping.size() > size1); - - int* addr2 = mapping.get_addr(); - REQUIRE(*addr2 == 42); - - mapping.unmap(); - - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); - } - - SECTION("remapping to smaller size should work") { - char filename[] = "test_mmap_shrink_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - - { - osmium::util::MemoryMapping mapping(8000, osmium::util::MemoryMapping::mapping_mode::write_shared, fd); - REQUIRE(mapping.size() >= 8000); - size_t size1 = mapping.size(); - - int* addr1 = mapping.get_addr(); - *addr1 = 42; - - mapping.resize(50); - REQUIRE(mapping.size() >= 50); - REQUIRE(mapping.size() < size1); - - int* addr2 = mapping.get_addr(); - REQUIRE(*addr2 == 42); - } - - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); - } -} - -TEST_CASE("typed anonymous mapping") { - - SECTION("simple memory mapping should work") { - osmium::util::TypedMemoryMapping mapping(1000); - volatile uint32_t* addr = mapping.begin(); - - REQUIRE(mapping.writable()); - - *addr = 42; - REQUIRE(*addr == 42); - - REQUIRE(!!mapping); - mapping.unmap(); - REQUIRE(!mapping); - mapping.unmap(); // second unmap is okay - } - - SECTION("moving a memory mapping should work") { - osmium::util::TypedMemoryMapping mapping1(1000); - uint32_t* addr1 = mapping1.begin(); - *addr1 = 42; - - REQUIRE(!!mapping1); - osmium::util::TypedMemoryMapping mapping2(std::move(mapping1)); - REQUIRE(!!mapping2); - REQUIRE(!mapping1); - mapping1.unmap(); - - auto addr2 = mapping2.begin(); - REQUIRE(*addr2 == 42); - - mapping2.unmap(); - REQUIRE(!mapping2); - } - - SECTION("move assignment should work") { - osmium::util::TypedMemoryMapping mapping1(1000); - osmium::util::TypedMemoryMapping mapping2(1000); - - REQUIRE(!!mapping1); - REQUIRE(!!mapping2); - - auto addr1 = mapping1.begin(); - *addr1 = 42; - - mapping2 = std::move(mapping1); - REQUIRE(!!mapping2); - REQUIRE(!mapping1); - - auto addr2 = mapping2.begin(); - REQUIRE(*addr2 == 42); - - mapping2.unmap(); - REQUIRE(!mapping2); - } - -#ifdef __linux__ - SECTION("remapping to larger size should work") { - osmium::util::TypedMemoryMapping mapping(1000); - REQUIRE(mapping.size() >= 1000); - - auto addr1 = mapping.begin(); - *addr1 = 42; - - mapping.resize(8000); - - auto addr2 = mapping.begin(); - REQUIRE(*addr2 == 42); - } - - SECTION("remapping to smaller size should work") { - osmium::util::TypedMemoryMapping mapping(8000); - REQUIRE(mapping.size() >= 8000); - - auto addr1 = mapping.begin(); - *addr1 = 42; - - mapping.resize(500); - - auto addr2 = mapping.begin(); - REQUIRE(*addr2 == 42); - } -#endif - -} - -TEST_CASE("typed file-based mapping") { - - SECTION("writing to a mapped file should work") { - char filename[] = "test_mmap_file_size_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - - osmium::util::resize_file(fd, 100); - - { - osmium::util::TypedMemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_shared, fd); - REQUIRE(mapping.writable()); - - REQUIRE(!!mapping); - REQUIRE(mapping.size() >= 100); - - *mapping.begin() = 1234; - - mapping.unmap(); - } - - { - osmium::util::TypedMemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::readonly, fd); - REQUIRE(!mapping.writable()); - - REQUIRE(!!mapping); - REQUIRE(mapping.size() >= 100); - REQUIRE(*mapping.begin() == 1234); - - mapping.unmap(); - } - - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); - } - -} - -TEST_CASE("anonymous memory mapping class") { - - SECTION("simple memory mapping should work") { - osmium::util::AnonymousMemoryMapping mapping(1000); - REQUIRE(mapping.get_addr() != nullptr); - - volatile int* addr = mapping.get_addr(); - - REQUIRE(mapping.writable()); - - *addr = 42; - REQUIRE(*addr == 42); - - REQUIRE(!!mapping); - mapping.unmap(); - REQUIRE(!mapping); - mapping.unmap(); // second unmap is okay - } - -#ifdef __linux__ - SECTION("remapping to larger size should work") { - osmium::util::AnonymousMemoryMapping mapping(1000); - REQUIRE(mapping.size() >= 1000); - - int* addr1 = mapping.get_addr(); - *addr1 = 42; - - mapping.resize(2000); - - int* addr2 = mapping.get_addr(); - REQUIRE(*addr2 == 42); - } - - SECTION("remapping to smaller size should work") { - osmium::util::AnonymousMemoryMapping mapping(2000); - REQUIRE(mapping.size() >= 2000); - - int* addr1 = mapping.get_addr(); - *addr1 = 42; - - mapping.resize(500); - - int* addr2 = mapping.get_addr(); - REQUIRE(*addr2 == 42); - } -#endif - -} - diff --git a/third_party/libosmium/test/t/util/test_minmax.cpp b/third_party/libosmium/test/t/util/test_minmax.cpp deleted file mode 100644 index 8b40f856e..000000000 --- a/third_party/libosmium/test/t/util/test_minmax.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "catch.hpp" - -#include -#include - -TEST_CASE("minmax numeric") { - - SECTION("min") { - osmium::min_op x; - REQUIRE(x() == std::numeric_limits::max()); - - x.update(17); - REQUIRE(x() == 17); - - x.update(10); - REQUIRE(x() == 10); - - x.update(22); - REQUIRE(x() == 10); - } - - SECTION("max") { - osmium::max_op x; - REQUIRE(x() == 0); - - x.update(17); - REQUIRE(x() == 17); - - x.update(10); - REQUIRE(x() == 17); - - x.update(22); - REQUIRE(x() == 22); - } - -} - -TEST_CASE("minmax timestamp") { - - SECTION("min") { - osmium::min_op x; - - x.update(osmium::Timestamp("2010-01-01T00:00:00Z")); - REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z"); - - x.update(osmium::Timestamp("2015-01-01T00:00:00Z")); - REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z"); - - x.update(osmium::Timestamp("2000-01-01T00:00:00Z")); - REQUIRE(x().to_iso() == "2000-01-01T00:00:00Z"); - } - - SECTION("max") { - osmium::max_op x; - - x.update(osmium::Timestamp("2010-01-01T00:00:00Z")); - REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z"); - - x.update(osmium::Timestamp("2015-01-01T00:00:00Z")); - REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z"); - - x.update(osmium::Timestamp("2000-01-01T00:00:00Z")); - REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z"); - - } - -} - diff --git a/third_party/libosmium/test/t/util/test_options.cpp b/third_party/libosmium/test/t/util/test_options.cpp deleted file mode 100644 index 8cba0950b..000000000 --- a/third_party/libosmium/test/t/util/test_options.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "catch.hpp" - -#include - -#include - -TEST_CASE("Options") { - - osmium::util::Options o; - - SECTION("set a single value from string") { - o.set("foo", "bar"); - REQUIRE("bar" == o.get("foo")); - REQUIRE("" == o.get("empty")); - REQUIRE("default" == o.get("empty", "default")); - - REQUIRE(!o.is_true("foo")); - REQUIRE(!o.is_true("empty")); - - REQUIRE(o.is_not_false("foo")); - REQUIRE(o.is_not_false("empty")); - - REQUIRE(1 == o.size()); - } - - SECTION("set values from booleans") { - o.set("t", true); - o.set("f", false); - REQUIRE("true" == o.get("t")); - REQUIRE("false" == o.get("f")); - REQUIRE("" == o.get("empty")); - - REQUIRE(o.is_true("t")); - REQUIRE(!o.is_true("f")); - - REQUIRE(o.is_not_false("t")); - REQUIRE(!o.is_not_false("f")); - - REQUIRE(2 == o.size()); - } - - SECTION("set value from string with equal sign") { - o.set("foo=bar"); - REQUIRE("bar" == o.get("foo")); - REQUIRE(1 == o.size()); - } - - SECTION("set value from string without equal sign") { - o.set("foo"); - REQUIRE("true" == o.get("foo")); - - REQUIRE(o.is_true("foo")); - REQUIRE(o.is_not_false("foo")); - - REQUIRE(1 == o.size()); - } - -} - -TEST_CASE("Options with initializer list") { - - osmium::util::Options o{ { "foo", "true" }, { "bar", "17" } }; - - REQUIRE(o.get("foo") == "true"); - REQUIRE(o.get("bar") == "17"); - REQUIRE(o.is_true("foo")); - REQUIRE_FALSE(o.is_true("bar")); - REQUIRE(o.size() == 2); - - SECTION("Change existing value") { - o.set("foo", "false"); - REQUIRE_FALSE(o.is_true("foo")); - } - - SECTION("Add new value") { - o.set("new", "something"); - REQUIRE_FALSE(o.is_true("new")); - REQUIRE(o.get("new") == "something"); - } -} - diff --git a/third_party/libosmium/test/t/util/test_string.cpp b/third_party/libosmium/test/t/util/test_string.cpp deleted file mode 100644 index 0960afe9a..000000000 --- a/third_party/libosmium/test/t/util/test_string.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "catch.hpp" - -#include - -TEST_CASE("split_string") { - - SECTION("split_string string") { - std::string str { "foo,baramba,baz" }; - std::vector result = {"foo", "baramba", "baz"}; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(result == osmium::split_string(str, ',', true)); - } - - SECTION("split_string string without sep") { - std::string str { "foo" }; - std::vector result = {"foo"}; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(result == osmium::split_string(str, ',', true)); - } - - SECTION("split_string string with empty at end") { - std::string str { "foo,bar," }; - std::vector result = {"foo", "bar", ""}; - std::vector resultc = {"foo", "bar"}; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(resultc == osmium::split_string(str, ',', true)); - } - - SECTION("split_string string with empty in middle") { - std::string str { "foo,,bar" }; - std::vector result = {"foo", "", "bar"}; - std::vector resultc = {"foo", "bar"}; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(resultc == osmium::split_string(str, ',', true)); - } - - SECTION("split_string string with empty at start") { - std::string str { ",bar,baz" }; - std::vector result = {"", "bar", "baz"}; - std::vector resultc = {"bar", "baz"}; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(resultc == osmium::split_string(str, ',', true)); - } - - SECTION("split_string sep") { - std::string str { "," }; - std::vector result = {"", ""}; - std::vector resultc; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(resultc == osmium::split_string(str, ',', true)); - } - - SECTION("split_string empty string") { - std::string str { "" }; - std::vector result; - - REQUIRE(result == osmium::split_string(str, ',')); - REQUIRE(result == osmium::split_string(str, ',', true)); - } - -} - diff --git a/third_party/libosmium/test/test_main.cpp b/third_party/libosmium/test/test_main.cpp deleted file mode 100644 index 0c7c351f4..000000000 --- a/third_party/libosmium/test/test_main.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "catch.hpp" diff --git a/third_party/libosmium/test/valgrind.supp b/third_party/libosmium/test/valgrind.supp deleted file mode 100644 index f6ef1f65a..000000000 --- a/third_party/libosmium/test/valgrind.supp +++ /dev/null @@ -1,47 +0,0 @@ -#----------------------------------------------------------------------------- -# -# This file describes messages that Valgrind should suppress, because they -# are about problems outside Libosmium that we can't fix anyway. -# -# See http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress -# -#----------------------------------------------------------------------------- - -{ - dl_error1 - Memcheck:Cond - fun:index - fun:expand_dynamic_string_token - fun:fillin_rpath - fun:_dl_init_paths - fun:dl_main - fun:_dl_sysdep_start - fun:_dl_start -} -{ - dl_error2 - Memcheck:Cond - fun:index - fun:expand_dynamic_string_token - fun:_dl_map_object - fun:map_doit - fun:_dl_catch_error - fun:do_preload - fun:dl_main - fun:_dl_sysdep_start - fun:_dl_start -} -{ - libpoppler_leak - Memcheck:Leak - fun:malloc - fun:gmalloc - fun:copyString -} -{ - tmpfile - Memcheck:Leak - fun:malloc - fun:fdopen@@GLIBC_* - fun:tmpfile@@GLIBC_* -}