First Commit
This commit is contained in:
commit
8a6c7106e3
1312 files changed
+425396
No files matched your search
@@ -0,0 +1 @@
|
||||
known_file_size text eol=lf
|
||||
@@ -0,0 +1 @@
|
||||
this file has size 22
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace detail {
|
||||
|
||||
static const char* env = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
static std::string name; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
|
||||
inline const char* getenv_wrapper(const char* var) noexcept {
|
||||
name = var;
|
||||
return env;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#define OSMIUM_TEST_RUNNER
|
||||
#include <osmium/util/config.hpp>
|
||||
|
||||
TEST_CASE("get_pool_threads") {
|
||||
osmium::detail::env = nullptr;
|
||||
REQUIRE(osmium::config::get_pool_threads() == 0);
|
||||
REQUIRE(osmium::detail::name == "OSMIUM_POOL_THREADS");
|
||||
osmium::detail::env = "";
|
||||
REQUIRE(osmium::config::get_pool_threads() == 0);
|
||||
osmium::detail::env = "2";
|
||||
REQUIRE(osmium::config::get_pool_threads() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("use_pool_threads_for_pbf_parsing") {
|
||||
osmium::detail::env = nullptr;
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
REQUIRE(osmium::detail::name == "OSMIUM_USE_POOL_THREADS_FOR_PBF_PARSING");
|
||||
osmium::detail::env = "";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
|
||||
osmium::detail::env = "off";
|
||||
REQUIRE_FALSE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "OFF";
|
||||
REQUIRE_FALSE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "false";
|
||||
REQUIRE_FALSE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "no";
|
||||
REQUIRE_FALSE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "No";
|
||||
REQUIRE_FALSE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "0";
|
||||
REQUIRE_FALSE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
|
||||
osmium::detail::env = "on";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "ON";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "true";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "yes";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "Yes";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
osmium::detail::env = "1";
|
||||
REQUIRE(osmium::config::use_pool_threads_for_pbf_parsing());
|
||||
}
|
||||
|
||||
TEST_CASE("get_max_queue_size") {
|
||||
osmium::detail::env = nullptr;
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 0) == 2);
|
||||
REQUIRE(osmium::detail::name == "OSMIUM_MAX_NAME_QUEUE_SIZE");
|
||||
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 7) == 7);
|
||||
|
||||
osmium::detail::env = "";
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 7) == 7);
|
||||
osmium::detail::env = "0";
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 7) == 7);
|
||||
osmium::detail::env = "3";
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 7) == 3);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/delta.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("delta encode int") {
|
||||
osmium::DeltaEncode<int> x;
|
||||
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.value() == 17);
|
||||
REQUIRE(x.update(10) == -7);
|
||||
REQUIRE(x.value() == 10);
|
||||
REQUIRE(x.update(-10) == -20);
|
||||
REQUIRE(x.value() == -10);
|
||||
x.clear();
|
||||
REQUIRE(x.value() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("delta encode int with int32") {
|
||||
osmium::DeltaEncode<int, int32_t> x;
|
||||
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.value() == 17);
|
||||
REQUIRE(x.update(10) == -7);
|
||||
REQUIRE(x.value() == 10);
|
||||
REQUIRE(x.update(-10) == -20);
|
||||
REQUIRE(x.value() == -10);
|
||||
x.clear();
|
||||
REQUIRE(x.value() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("delta decode int") {
|
||||
osmium::DeltaDecode<int> x;
|
||||
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.value() == 17);
|
||||
REQUIRE(x.update(10) == 27);
|
||||
REQUIRE(x.value() == 27);
|
||||
REQUIRE(x.update(-40) == -13);
|
||||
REQUIRE(x.value() == -13);
|
||||
x.clear();
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.value() == 17);
|
||||
}
|
||||
|
||||
TEST_CASE("delta decode int with int32") {
|
||||
osmium::DeltaDecode<int, int32_t> x;
|
||||
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.update(10) == 27);
|
||||
REQUIRE(x.update(-40) == -13);
|
||||
x.clear();
|
||||
REQUIRE(x.update(17) == 17);
|
||||
}
|
||||
|
||||
TEST_CASE("delta encode unsigned int") {
|
||||
osmium::DeltaEncode<unsigned int> x;
|
||||
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.update(10) == -7);
|
||||
REQUIRE(x.update(0) == -10);
|
||||
}
|
||||
|
||||
TEST_CASE("delta decode unsigned int") {
|
||||
osmium::DeltaDecode<unsigned int> x;
|
||||
|
||||
REQUIRE(x.update(17) == 17);
|
||||
REQUIRE(x.update(10) == 27);
|
||||
REQUIRE(x.update(-15) == 12);
|
||||
}
|
||||
|
||||
TEST_CASE("delta encode and decode") {
|
||||
const std::vector<int> a = { 5, -9, 22, 13, 0, 23 };
|
||||
|
||||
osmium::DeltaEncode<int, int> de;
|
||||
std::vector<int> b;
|
||||
b.reserve(a.size());
|
||||
for (const int x : a) {
|
||||
b.push_back(de.update(x));
|
||||
}
|
||||
|
||||
osmium::DeltaDecode<int, int> dd;
|
||||
std::vector<int> c;
|
||||
c.reserve(b.size());
|
||||
for (const int x : b) {
|
||||
c.push_back(dd.update(x));
|
||||
}
|
||||
|
||||
REQUIRE(a == c);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/double.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Check double2string function") {
|
||||
std::string s1;
|
||||
osmium::double2string(s1, 1.123, 7);
|
||||
REQUIRE(s1 == "1.123");
|
||||
|
||||
std::string s2;
|
||||
osmium::double2string(s2, 1.000, 7);
|
||||
REQUIRE(s2 == "1");
|
||||
|
||||
std::string s3;
|
||||
osmium::double2string(s3, 0.0, 7);
|
||||
REQUIRE(s3 == "0");
|
||||
|
||||
std::string s4;
|
||||
osmium::double2string(s4, 0.020, 7);
|
||||
REQUIRE(s4 == "0.02");
|
||||
|
||||
std::string s5;
|
||||
osmium::double2string(s5, -0.020, 7);
|
||||
REQUIRE(s5 == "-0.02");
|
||||
|
||||
std::string s6;
|
||||
osmium::double2string(s6, -0.0, 7);
|
||||
REQUIRE(s6 == "-0");
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <osmium/io/detail/read_write.hpp>
|
||||
#include <osmium/util/file.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("file_size(int) and file_offset() of known file") {
|
||||
const std::string file_name{with_data_dir("t/util/known_file_size")};
|
||||
const int fd = osmium::io::detail::open_for_reading(file_name);
|
||||
REQUIRE(fd > 0);
|
||||
REQUIRE(osmium::file_size(fd) == 22);
|
||||
REQUIRE(osmium::file_offset(fd) == 0);
|
||||
REQUIRE_FALSE(osmium::isatty(fd));
|
||||
}
|
||||
|
||||
TEST_CASE("file_size(std::string) of known file") {
|
||||
const std::string file_name{with_data_dir("t/util/known_file_size")};
|
||||
REQUIRE(osmium::file_size(file_name) == 22);
|
||||
}
|
||||
|
||||
TEST_CASE("file_size(const char*) of known file") {
|
||||
const std::string file_name{with_data_dir("t/util/known_file_size")};
|
||||
REQUIRE(osmium::file_size(file_name.c_str()) == 22);
|
||||
}
|
||||
|
||||
TEST_CASE("file_size() with illegal fd should throw") {
|
||||
REQUIRE_THROWS_AS(osmium::file_size(-1), std::system_error);
|
||||
}
|
||||
|
||||
TEST_CASE("file_size() with unused fd should throw") {
|
||||
// its unlikely that fd 1000 is open...
|
||||
REQUIRE_THROWS_AS(osmium::file_size(1000), std::system_error);
|
||||
}
|
||||
|
||||
TEST_CASE("file_size() of unknown file should throw") {
|
||||
REQUIRE_THROWS_AS(osmium::file_size("unknown file"), std::system_error);
|
||||
}
|
||||
|
||||
TEST_CASE("resize_file() with illegal fd should throw") {
|
||||
REQUIRE_THROWS_AS(osmium::resize_file(-1, 10), std::system_error);
|
||||
}
|
||||
|
||||
TEST_CASE("resize_file() with unused fd should throw") {
|
||||
// its unlikely that fd 1000 is open...
|
||||
REQUIRE_THROWS_AS(osmium::resize_file(1000, 10), std::system_error);
|
||||
}
|
||||
|
||||
TEST_CASE("get_pagesize()") {
|
||||
REQUIRE(osmium::get_pagesize() > 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/memory.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("Check memory usage") {
|
||||
#ifdef __linux__
|
||||
const osmium::MemoryUsage m1;
|
||||
REQUIRE(m1.current() > 1);
|
||||
REQUIRE(m1.peak() > 1);
|
||||
#else
|
||||
const osmium::MemoryUsage m;
|
||||
REQUIRE(m.current() == 0);
|
||||
REQUIRE(m.peak() == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,410 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/file.hpp>
|
||||
#include <osmium/util/memory_mapping.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
|
||||
#include "win_mkstemp.hpp"
|
||||
#endif
|
||||
|
||||
TEST_CASE("Anonymous mapping: simple memory mapping should work") {
|
||||
osmium::MemoryMapping mapping{1000, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
REQUIRE(mapping.get_addr() != nullptr);
|
||||
|
||||
REQUIRE(mapping.size() >= 1000);
|
||||
|
||||
volatile int* addr = mapping.get_addr<int>();
|
||||
|
||||
REQUIRE(mapping.writable());
|
||||
|
||||
*addr = 42;
|
||||
REQUIRE(*addr == 42);
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
mapping.unmap();
|
||||
REQUIRE(!mapping);
|
||||
mapping.unmap(); // second unmap is okay
|
||||
}
|
||||
|
||||
TEST_CASE("Anonymous mapping: memory mapping of zero length should result in memory mapping of pagesize length") {
|
||||
const osmium::MemoryMapping mapping{0, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
REQUIRE(mapping.size() == osmium::get_pagesize());
|
||||
}
|
||||
|
||||
TEST_CASE("Anonymous mapping: moving a memory mapping should work") {
|
||||
osmium::MemoryMapping mapping1{1000, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
auto* addr1 = mapping1.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
REQUIRE(!!mapping1);
|
||||
osmium::MemoryMapping mapping2{std::move(mapping1)};
|
||||
REQUIRE(!!mapping2);
|
||||
REQUIRE(!mapping1); // NOLINT(bugprone-use-after-move,misc-use-after-move) okay here, we are checking our own code
|
||||
mapping1.unmap(); // NOLINT(clang-analyzer-cplusplus.Move) okay here, we are checking our own code
|
||||
|
||||
const auto* addr2 = mapping2.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
|
||||
mapping2.unmap();
|
||||
REQUIRE(!mapping2);
|
||||
}
|
||||
|
||||
TEST_CASE("Anonymous mapping: move assignment should work") {
|
||||
osmium::MemoryMapping mapping1{1000, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
osmium::MemoryMapping mapping2{1000, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
|
||||
REQUIRE(!!mapping1);
|
||||
REQUIRE(!!mapping2);
|
||||
|
||||
auto* addr1 = mapping1.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping2 = std::move(mapping1);
|
||||
REQUIRE(!!mapping2);
|
||||
// cppcheck-suppress accessMoved
|
||||
REQUIRE(!mapping1); // NOLINT(bugprone-use-after-move,misc-use-after-move) okay here, we are checking our own code
|
||||
|
||||
const auto* addr2 = mapping2.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
|
||||
mapping2.unmap();
|
||||
REQUIRE(!mapping2);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
TEST_CASE("Anonymous mapping: remapping to larger size should work") {
|
||||
osmium::MemoryMapping mapping{1000, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
REQUIRE(mapping.size() >= 1000);
|
||||
|
||||
const size_t size1 = mapping.size();
|
||||
|
||||
auto* addr1 = mapping.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(8000);
|
||||
REQUIRE(mapping.size() > size1);
|
||||
|
||||
const auto* addr2 = mapping.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
|
||||
TEST_CASE("Anonymous mapping: remapping to smaller size should work") {
|
||||
osmium::MemoryMapping mapping{8000, osmium::MemoryMapping::mapping_mode::write_private};
|
||||
REQUIRE(mapping.size() >= 1000);
|
||||
|
||||
const size_t size1 = mapping.size();
|
||||
|
||||
auto* addr1 = mapping.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(500);
|
||||
REQUIRE(mapping.size() < size1);
|
||||
|
||||
const auto* addr2 = mapping.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("File-based mapping: writing to a mapped file should work") {
|
||||
char filename[] = "test_mmap_write_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::resize_file(fd, 100);
|
||||
|
||||
{
|
||||
osmium::MemoryMapping mapping{100, osmium::MemoryMapping::mapping_mode::write_shared, fd};
|
||||
REQUIRE(mapping.writable());
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
REQUIRE(mapping.size() >= 100);
|
||||
|
||||
*mapping.get_addr<int>() = 1234;
|
||||
|
||||
mapping.unmap();
|
||||
}
|
||||
|
||||
REQUIRE(osmium::file_size(fd) == 100);
|
||||
|
||||
{
|
||||
osmium::MemoryMapping mapping{100, osmium::MemoryMapping::mapping_mode::readonly, fd};
|
||||
REQUIRE_FALSE(mapping.writable());
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
REQUIRE(mapping.size() >= 100);
|
||||
REQUIRE(*mapping.get_addr<int>() == 1234);
|
||||
|
||||
mapping.unmap();
|
||||
}
|
||||
|
||||
REQUIRE(0 == close(fd));
|
||||
REQUIRE(0 == unlink(filename));
|
||||
}
|
||||
|
||||
TEST_CASE("File-based mapping: Reading from a zero-sized mapped file should work") {
|
||||
char filename[] = "test_mmap_read_zero_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
{
|
||||
osmium::MemoryMapping mapping{0, osmium::MemoryMapping::mapping_mode::readonly, fd};
|
||||
REQUIRE(mapping.size() > 0);
|
||||
mapping.unmap();
|
||||
}
|
||||
|
||||
REQUIRE(0 == close(fd));
|
||||
REQUIRE(0 == unlink(filename));
|
||||
}
|
||||
|
||||
TEST_CASE("File-based mapping: writing to a privately mapped file should work") {
|
||||
char filename[] = "test_mmap_write_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::resize_file(fd, 100);
|
||||
|
||||
{
|
||||
osmium::MemoryMapping mapping{100, osmium::MemoryMapping::mapping_mode::write_private, fd};
|
||||
REQUIRE(mapping.writable());
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
REQUIRE(mapping.size() >= 100);
|
||||
|
||||
*mapping.get_addr<int>() = 1234;
|
||||
|
||||
mapping.unmap();
|
||||
}
|
||||
|
||||
REQUIRE(osmium::file_size(fd) == 100);
|
||||
|
||||
{
|
||||
osmium::MemoryMapping mapping{100, osmium::MemoryMapping::mapping_mode::readonly, fd};
|
||||
REQUIRE_FALSE(mapping.writable());
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
REQUIRE(mapping.size() >= 100);
|
||||
REQUIRE(*mapping.get_addr<int>() == 0); // should not see the value set above
|
||||
|
||||
mapping.unmap();
|
||||
}
|
||||
|
||||
REQUIRE(0 == close(fd));
|
||||
REQUIRE(0 == unlink(filename));
|
||||
}
|
||||
|
||||
TEST_CASE("File-based mapping: remapping to larger size should work") {
|
||||
char filename[] = "test_mmap_grow_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::MemoryMapping mapping{100, osmium::MemoryMapping::mapping_mode::write_shared, fd};
|
||||
REQUIRE(mapping.size() >= 100);
|
||||
const size_t size1 = mapping.size();
|
||||
|
||||
auto* addr1 = mapping.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(8000);
|
||||
REQUIRE(mapping.size() >= 8000);
|
||||
REQUIRE(mapping.size() > size1);
|
||||
|
||||
const auto* addr2 = mapping.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
|
||||
mapping.unmap();
|
||||
|
||||
REQUIRE(0 == close(fd));
|
||||
REQUIRE(0 == unlink(filename));
|
||||
}
|
||||
|
||||
TEST_CASE("File-based mapping: remapping to smaller size should work") {
|
||||
char filename[] = "test_mmap_shrink_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
{
|
||||
osmium::MemoryMapping mapping{8000, osmium::MemoryMapping::mapping_mode::write_shared, fd};
|
||||
REQUIRE(mapping.size() >= 8000);
|
||||
const size_t size1 = mapping.size();
|
||||
|
||||
auto* addr1 = mapping.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(50);
|
||||
REQUIRE(mapping.size() >= 50);
|
||||
REQUIRE(mapping.size() < size1);
|
||||
|
||||
const auto* addr2 = mapping.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
|
||||
REQUIRE(0 == close(fd));
|
||||
REQUIRE(0 == unlink(filename));
|
||||
}
|
||||
|
||||
TEST_CASE("Typed anonymous mapping: simple memory mapping should work") {
|
||||
osmium::TypedMemoryMapping<uint32_t> 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
|
||||
}
|
||||
|
||||
TEST_CASE("Typed anonymous mapping: moving a memory mapping should work") {
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping1{1000};
|
||||
uint32_t* addr1 = mapping1.begin();
|
||||
*addr1 = 42;
|
||||
|
||||
REQUIRE(!!mapping1);
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping2{std::move(mapping1)};
|
||||
REQUIRE(!!mapping2);
|
||||
REQUIRE(!mapping1); // NOLINT(bugprone-use-after-move,misc-use-after-move) okay here, we are checking our own code
|
||||
mapping1.unmap(); // NOLINT(clang-analyzer-cplusplus.Move) okay here, we are checking our own code
|
||||
|
||||
const auto* const addr2 = mapping2.begin();
|
||||
REQUIRE(*addr2 == 42);
|
||||
|
||||
mapping2.unmap();
|
||||
REQUIRE(!mapping2);
|
||||
}
|
||||
|
||||
TEST_CASE("Typed anonymous mapping: move assignment should work") {
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping1{1000};
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping2{1000};
|
||||
|
||||
REQUIRE(!!mapping1);
|
||||
REQUIRE(!!mapping2);
|
||||
|
||||
auto* const addr1 = mapping1.begin();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping2 = std::move(mapping1);
|
||||
REQUIRE(!!mapping2);
|
||||
// cppcheck-suppress accessMoved
|
||||
REQUIRE(!mapping1); // NOLINT(bugprone-use-after-move,misc-use-after-move) okay here, we are checking our own code
|
||||
|
||||
const auto* const addr2 = mapping2.begin();
|
||||
REQUIRE(*addr2 == 42);
|
||||
|
||||
mapping2.unmap();
|
||||
REQUIRE(!mapping2);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
TEST_CASE("Typed anonymous mapping: remapping to larger size should work") {
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping{1000};
|
||||
REQUIRE(mapping.size() >= 1000);
|
||||
|
||||
auto* const addr1 = mapping.begin();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(8000);
|
||||
|
||||
const auto* const addr2 = mapping.begin();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
|
||||
TEST_CASE("Typed anonymous mapping: remapping to smaller size should work") {
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping{8000};
|
||||
REQUIRE(mapping.size() >= 8000);
|
||||
|
||||
auto* const addr1 = mapping.begin();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(500);
|
||||
|
||||
const auto* const addr2 = mapping.begin();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Typed file-based mapping: writing to a mapped file should work") {
|
||||
char filename[] = "test_mmap_file_size_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::resize_file(fd, 100);
|
||||
|
||||
{
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping{100, osmium::MemoryMapping::mapping_mode::write_shared, fd};
|
||||
REQUIRE(mapping.writable());
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
REQUIRE(mapping.size() >= 100);
|
||||
|
||||
*mapping.begin() = 1234;
|
||||
|
||||
mapping.unmap();
|
||||
}
|
||||
|
||||
{
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping{100, osmium::MemoryMapping::mapping_mode::readonly, fd};
|
||||
REQUIRE_FALSE(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: simple memory mapping should work") {
|
||||
osmium::AnonymousMemoryMapping mapping{1000};
|
||||
REQUIRE(mapping.get_addr() != nullptr);
|
||||
|
||||
volatile int* addr = mapping.get_addr<int>();
|
||||
|
||||
REQUIRE(mapping.writable());
|
||||
|
||||
*addr = 42;
|
||||
REQUIRE(*addr == 42);
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
mapping.unmap();
|
||||
REQUIRE(!mapping);
|
||||
mapping.unmap(); // second unmap is okay
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
TEST_CASE("Anonymous memory mapping class: remapping to larger size should work") {
|
||||
osmium::AnonymousMemoryMapping mapping{1000};
|
||||
REQUIRE(mapping.size() >= 1000);
|
||||
|
||||
auto* addr1 = mapping.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(2000);
|
||||
|
||||
const auto* addr2 = mapping.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
|
||||
TEST_CASE("Anonymous memory mapping class: remapping to smaller size should work") {
|
||||
osmium::AnonymousMemoryMapping mapping{2000};
|
||||
REQUIRE(mapping.size() >= 2000);
|
||||
|
||||
auto* addr1 = mapping.get_addr<int>();
|
||||
*addr1 = 42;
|
||||
|
||||
mapping.resize(500);
|
||||
|
||||
const auto* addr2 = mapping.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/util/minmax.hpp>
|
||||
|
||||
#include <limits>
|
||||
|
||||
TEST_CASE("min_op numeric") {
|
||||
osmium::min_op<int> x;
|
||||
REQUIRE(x() == std::numeric_limits<int>::max());
|
||||
|
||||
x.update(17);
|
||||
REQUIRE(x() == 17);
|
||||
|
||||
x.update(10);
|
||||
REQUIRE(x() == 10);
|
||||
|
||||
x.update(22);
|
||||
REQUIRE(x() == 10);
|
||||
}
|
||||
|
||||
TEST_CASE("max_op numeric") {
|
||||
osmium::max_op<uint32_t> x;
|
||||
REQUIRE(x() == 0);
|
||||
|
||||
x.update(17);
|
||||
REQUIRE(x() == 17);
|
||||
|
||||
x.update(10);
|
||||
REQUIRE(x() == 17);
|
||||
|
||||
x.update(22);
|
||||
REQUIRE(x() == 22);
|
||||
}
|
||||
|
||||
TEST_CASE("min_op timestamp") {
|
||||
osmium::min_op<osmium::Timestamp> 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");
|
||||
}
|
||||
|
||||
TEST_CASE("max_op timestamp") {
|
||||
osmium::max_op<osmium::Timestamp> 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");
|
||||
}
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/misc.hpp>
|
||||
|
||||
template <typename T>
|
||||
void test_conv() {
|
||||
REQUIRE(osmium::detail::str_to_int<T>("0") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("1") == 1);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("9") == 9);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("10") == 10);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("44") == 44);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("45") == 45);
|
||||
REQUIRE(osmium::detail::str_to_int<T>(" 123") == 123);
|
||||
|
||||
REQUIRE(osmium::detail::str_to_int<T>("-1") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("-100") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("1 ") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("x1") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("1x") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("2 3") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<T>("9999999999999999999999") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("string to integer conversion") {
|
||||
test_conv<int>();
|
||||
test_conv<unsigned int>();
|
||||
|
||||
test_conv<int8_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<int8_t>("126") == 126);
|
||||
REQUIRE(osmium::detail::str_to_int<int8_t>("127") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<int8_t>("128") == 0);
|
||||
|
||||
test_conv<uint8_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<uint8_t>("254") == 254);
|
||||
REQUIRE(osmium::detail::str_to_int<uint8_t>("255") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<uint8_t>("256") == 0);
|
||||
|
||||
test_conv<int16_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<int16_t>("32766") == 32766);
|
||||
REQUIRE(osmium::detail::str_to_int<int16_t>("32767") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<int16_t>("32768") == 0);
|
||||
|
||||
test_conv<uint16_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<uint16_t>("65534") == 65534);
|
||||
REQUIRE(osmium::detail::str_to_int<uint16_t>("65535") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<uint16_t>("65536") == 0);
|
||||
|
||||
test_conv<int32_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483646") == 2147483646LL);
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483647") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483648") == 0);
|
||||
|
||||
test_conv<uint32_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967294") == 4294967294ULL);
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967295") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967296") == 0);
|
||||
|
||||
test_conv<int64_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775806") == 9223372036854775806LL);
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775807") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775808") == 0);
|
||||
|
||||
test_conv<uint64_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775806") == 9223372036854775806ULL);
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775807") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775808") == 0);
|
||||
}
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/options.hpp>
|
||||
|
||||
TEST_CASE("Set a single option value from string") {
|
||||
osmium::Options o;
|
||||
|
||||
REQUIRE(o.empty());
|
||||
|
||||
o.set("foo", "bar");
|
||||
REQUIRE("bar" == o.get("foo"));
|
||||
REQUIRE(o.get("empty").empty());
|
||||
REQUIRE("default" == o.get("empty", "default"));
|
||||
|
||||
REQUIRE_FALSE(o.is_true("foo"));
|
||||
REQUIRE_FALSE(o.is_true("empty"));
|
||||
|
||||
REQUIRE(o.is_not_false("foo"));
|
||||
REQUIRE(o.is_not_false("empty"));
|
||||
|
||||
REQUIRE(1 == o.size());
|
||||
REQUIRE_FALSE(o.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Set option values from booleans") {
|
||||
osmium::Options o;
|
||||
|
||||
o.set("t", true);
|
||||
o.set("f", false);
|
||||
REQUIRE("true" == o.get("t"));
|
||||
REQUIRE("false" == o.get("f"));
|
||||
REQUIRE(o.get("empty").empty());
|
||||
|
||||
REQUIRE(o.is_true("t"));
|
||||
REQUIRE_FALSE(o.is_true("f"));
|
||||
|
||||
REQUIRE(o.is_not_false("t"));
|
||||
REQUIRE_FALSE(o.is_not_false("f"));
|
||||
|
||||
REQUIRE(2 == o.size());
|
||||
}
|
||||
|
||||
TEST_CASE("Set option value from string with equal sign") {
|
||||
osmium::Options o;
|
||||
|
||||
o.set("foo=bar");
|
||||
REQUIRE("bar" == o.get("foo"));
|
||||
REQUIRE(1 == o.size());
|
||||
}
|
||||
|
||||
TEST_CASE("Set option value from string without equal sign") {
|
||||
osmium::Options o;
|
||||
|
||||
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::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");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Iterating over options") {
|
||||
/*not const*/ osmium::Options o{{ "foo", "true" }, { "bar", "17" }};
|
||||
|
||||
auto it = o.begin();
|
||||
REQUIRE(it->first == "bar");
|
||||
REQUIRE(it->second == "17");
|
||||
++it;
|
||||
REQUIRE(it->first == "foo");
|
||||
REQUIRE(it->second == "true");
|
||||
++it;
|
||||
REQUIRE(it == o.end());
|
||||
}
|
||||
|
||||
TEST_CASE("Const iterating over options") {
|
||||
const osmium::Options o{{ "foo", "true" }, { "bar", "17" }};
|
||||
|
||||
SECTION("begin/end") {
|
||||
auto it = o.begin();
|
||||
REQUIRE(it->first == "bar");
|
||||
REQUIRE(it->second == "17");
|
||||
++it;
|
||||
REQUIRE(it->first == "foo");
|
||||
REQUIRE(it->second == "true");
|
||||
++it;
|
||||
REQUIRE(it == o.end());
|
||||
}
|
||||
SECTION("cbegin/cend") {
|
||||
auto it = o.cbegin();
|
||||
REQUIRE(it->first == "bar");
|
||||
REQUIRE(it->second == "17");
|
||||
++it;
|
||||
REQUIRE(it->first == "foo");
|
||||
REQUIRE(it->second == "true");
|
||||
++it;
|
||||
REQUIRE(it == o.cend());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/string.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("split_string string") {
|
||||
const std::string str{"foo,baramba,baz"};
|
||||
const std::vector<std::string> result = {"foo", "baramba", "baz"};
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(result == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ",;"));
|
||||
REQUIRE(result == osmium::split_string(str, ",;", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string string without sep") {
|
||||
const std::string str{"foo"};
|
||||
const std::vector<std::string> result = {"foo"};
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(result == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ",;"));
|
||||
REQUIRE(result == osmium::split_string(str, ",;", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string string with empty at end") {
|
||||
const std::string str{"foo,bar,"};
|
||||
const std::vector<std::string> result = {"foo", "bar", ""};
|
||||
const std::vector<std::string> resultc = {"foo", "bar"};
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(resultc == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ";,"));
|
||||
REQUIRE(resultc == osmium::split_string(str, ";,", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string string with empty in middle") {
|
||||
const std::string str{"foo,,bar"};
|
||||
const std::vector<std::string> result = {"foo", "", "bar"};
|
||||
const std::vector<std::string> resultc = {"foo", "bar"};
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(resultc == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ",;"));
|
||||
REQUIRE(resultc == osmium::split_string(str, ";,", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string string with empty at start") {
|
||||
const std::string str{",bar,baz"};
|
||||
const std::vector<std::string> result = {"", "bar", "baz"};
|
||||
const std::vector<std::string> resultc = {"bar", "baz"};
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(resultc == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ";,"));
|
||||
REQUIRE(resultc == osmium::split_string(str, ",;", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string sep") {
|
||||
const std::string str{","};
|
||||
const std::vector<std::string> result = {"", ""};
|
||||
const std::vector<std::string> resultc;
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(resultc == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ",;"));
|
||||
REQUIRE(resultc == osmium::split_string(str, ",;", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string empty string") {
|
||||
const std::string str{};
|
||||
const std::vector<std::string> result;
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ','));
|
||||
REQUIRE(result == osmium::split_string(str, ',', true));
|
||||
REQUIRE(result == osmium::split_string(str, ",;"));
|
||||
REQUIRE(result == osmium::split_string(str, ",;", true));
|
||||
}
|
||||
|
||||
TEST_CASE("split_string string with multiple sep characters") {
|
||||
const std::string str{"foo,bar;baz-,blub"};
|
||||
const std::vector<std::string> result = {"foo", "bar", "baz", "", "blub"};
|
||||
|
||||
REQUIRE(result == osmium::split_string(str, ";,-"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/string_matcher.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#ifdef OSMIUM_WITH_REGEX
|
||||
#include <regex>
|
||||
#endif
|
||||
|
||||
static_assert(std::is_default_constructible<osmium::StringMatcher>::value, "StringMatcher should be default constructible");
|
||||
static_assert(std::is_copy_constructible<osmium::StringMatcher>::value, "StringMatcher should be copy constructible");
|
||||
static_assert(std::is_move_constructible<osmium::StringMatcher>::value, "StringMatcher should be move constructible");
|
||||
static_assert(std::is_copy_assignable<osmium::StringMatcher>::value, "StringMatcher should be copyable");
|
||||
static_assert(std::is_move_assignable<osmium::StringMatcher>::value, "StringMatcher should be moveable");
|
||||
|
||||
template <typename T>
|
||||
std::string print(const T& matcher) {
|
||||
std::stringstream ss;
|
||||
ss << matcher;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: always false") {
|
||||
const osmium::StringMatcher::always_false m;
|
||||
REQUIRE_FALSE(m.match("foo"));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: always true") {
|
||||
const osmium::StringMatcher::always_true m;
|
||||
REQUIRE(m.match("foo"));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: equal") {
|
||||
const osmium::StringMatcher::equal m{"foo"};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE_FALSE(m.match("foobar"));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: prefix from const char*") {
|
||||
const osmium::StringMatcher::prefix m{"foo"};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE_FALSE(m.match(""));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: prefix from std::string") {
|
||||
const std::string v{"foo"};
|
||||
const osmium::StringMatcher::prefix m{v};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE_FALSE(m.match(""));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: substring from const char*") {
|
||||
const osmium::StringMatcher::substring m{"foo"};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE(m.match("barfoo"));
|
||||
REQUIRE(m.match("xfoox"));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: substring from std::string") {
|
||||
const std::string v{"foo"};
|
||||
const osmium::StringMatcher::substring m{v};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE(m.match("barfoo"));
|
||||
REQUIRE(m.match("xfoox"));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: empty prefix") {
|
||||
const osmium::StringMatcher::prefix m{""};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE(m.match(""));
|
||||
}
|
||||
|
||||
#ifdef OSMIUM_WITH_REGEX
|
||||
TEST_CASE("String matcher: regex prefix") {
|
||||
const osmium::StringMatcher::regex m{std::regex{"^foo", std::regex::optimize}};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE_FALSE(m.match(""));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: regex substr") {
|
||||
const osmium::StringMatcher::regex m{std::regex{"foo", std::regex::optimize}};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
REQUIRE(m.match("foobar"));
|
||||
REQUIRE(m.match("xfoox"));
|
||||
REQUIRE_FALSE(m.match(""));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("String matcher: list") {
|
||||
const osmium::StringMatcher::list m{{"foo", "bar"}};
|
||||
REQUIRE(m.match("foo"));
|
||||
REQUIRE(m.match("bar"));
|
||||
REQUIRE_FALSE(m.match("foobar"));
|
||||
REQUIRE_FALSE(m.match("baz"));
|
||||
REQUIRE_FALSE(m.match(""));
|
||||
}
|
||||
|
||||
TEST_CASE("String matcher: list with add") {
|
||||
osmium::StringMatcher::list m;
|
||||
REQUIRE_FALSE(m.match("foo"));
|
||||
REQUIRE_FALSE(m.match("bar"));
|
||||
m.add_string("foo");
|
||||
REQUIRE(m.match("foo"));
|
||||
m.add_string(std::string{"bar"});
|
||||
REQUIRE(m.match("bar"));
|
||||
REQUIRE_FALSE(m.match("foobar"));
|
||||
REQUIRE_FALSE(m.match("baz"));
|
||||
REQUIRE_FALSE(m.match(""));
|
||||
}
|
||||
|
||||
TEST_CASE("Default constructed StringMatcher matches nothing") {
|
||||
const osmium::StringMatcher m;
|
||||
REQUIRE_FALSE(m("foo"));
|
||||
REQUIRE_FALSE(m("bar"));
|
||||
REQUIRE(print(m) == "always_false");
|
||||
}
|
||||
|
||||
TEST_CASE("Construct StringMatcher from bool") {
|
||||
const osmium::StringMatcher m1{false};
|
||||
REQUIRE_FALSE(m1("foo"));
|
||||
REQUIRE_FALSE(m1("bar"));
|
||||
REQUIRE(print(m1) == "always_false");
|
||||
|
||||
const osmium::StringMatcher m2{true};
|
||||
REQUIRE(m2("foo"));
|
||||
REQUIRE(m2("bar"));
|
||||
REQUIRE(print(m2) == "always_true");
|
||||
}
|
||||
|
||||
TEST_CASE("Construct StringMatcher from string") {
|
||||
const osmium::StringMatcher m{"foo"};
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE_FALSE(m("bar"));
|
||||
REQUIRE(print(m) == "equal[foo]");
|
||||
}
|
||||
|
||||
#ifdef OSMIUM_WITH_REGEX
|
||||
TEST_CASE("Construct StringMatcher from regex") {
|
||||
const osmium::StringMatcher m{std::regex{"^foo"}};
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE_FALSE(m("bar"));
|
||||
REQUIRE(print(m) == "regex");
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Construct StringMatcher from list") {
|
||||
const std::vector<std::string> v{"foo", "xxx"};
|
||||
const osmium::StringMatcher m{v};
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE_FALSE(m("bar"));
|
||||
REQUIRE(print(m) == "list[[foo][xxx]]");
|
||||
}
|
||||
|
||||
TEST_CASE("Construct StringMatcher") {
|
||||
osmium::StringMatcher m{osmium::StringMatcher::equal{"foo"}};
|
||||
REQUIRE(print(m) == "equal[foo]");
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE_FALSE(m("bar"));
|
||||
|
||||
m = osmium::StringMatcher::list{{"foo", "bar"}};
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE(m(std::string{"bar"}));
|
||||
REQUIRE(print(m) == "list[[foo][bar]]");
|
||||
|
||||
m = osmium::StringMatcher::prefix{"foo"};
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE(m("foobar"));
|
||||
REQUIRE_FALSE(m("barfoo"));
|
||||
REQUIRE(print(m) == "prefix[foo]");
|
||||
|
||||
m = osmium::StringMatcher::substring{"foo"};
|
||||
REQUIRE(m("foo"));
|
||||
REQUIRE(m("foobar"));
|
||||
REQUIRE(m(std::string{"barfoo"}));
|
||||
REQUIRE(print(m) == "substring[foo]");
|
||||
}
|
||||
|
||||
TEST_CASE("Copy construct StringMatcher") {
|
||||
const osmium::StringMatcher m1{"foo"};
|
||||
const osmium::StringMatcher m2{m1}; // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
REQUIRE(print(m1) == "equal[foo]");
|
||||
REQUIRE(print(m2) == "equal[foo]");
|
||||
}
|
||||
|
||||
TEST_CASE("Copy assign StringMatcher") {
|
||||
const osmium::StringMatcher m1{"foo"};
|
||||
osmium::StringMatcher m2{"bar"};
|
||||
m2 = m1;
|
||||
|
||||
REQUIRE(print(m1) == "equal[foo]");
|
||||
REQUIRE(print(m2) == "equal[foo]");
|
||||
}
|
||||
|
||||
TEST_CASE("Move construct StringMatcher") {
|
||||
osmium::StringMatcher m1{"foo"};
|
||||
const osmium::StringMatcher m2{std::move(m1)};
|
||||
|
||||
REQUIRE(print(m2) == "equal[foo]");
|
||||
}
|
||||
|
||||
TEST_CASE("Move assign StringMatcher") {
|
||||
osmium::StringMatcher m1{"foo"};
|
||||
osmium::StringMatcher m2{"bar"};
|
||||
m2 = std::move(m1);
|
||||
|
||||
REQUIRE(print(m2) == "equal[foo]");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/util/timer.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
TEST_CASE("timer") {
|
||||
osmium::Timer timer;
|
||||
timer.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
timer.stop();
|
||||
REQUIRE(timer.elapsed_microseconds() == 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#define OSMIUM_WITH_TIMER
|
||||
#include <osmium/util/timer.hpp>
|
||||
|
||||
TEST_CASE("timer") {
|
||||
osmium::Timer timer;
|
||||
timer.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
timer.stop();
|
||||
REQUIRE(timer.elapsed_microseconds() > 900);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user