1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include "catch.hpp"
#include "utils.hpp"
#include <osmium/io/detail/read_write.hpp>
#include <osmium/util/file.hpp>
#include <string>
#include <system_error>
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(999), 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);
}
|