#include "catch.hpp" #include template void test_conv() { REQUIRE(osmium::detail::str_to_int("0") == 0); REQUIRE(osmium::detail::str_to_int("1") == 1); REQUIRE(osmium::detail::str_to_int("9") == 9); REQUIRE(osmium::detail::str_to_int("10") == 10); REQUIRE(osmium::detail::str_to_int("44") == 44); REQUIRE(osmium::detail::str_to_int("45") == 45); REQUIRE(osmium::detail::str_to_int(" 123") == 123); REQUIRE(osmium::detail::str_to_int("-1") == 0); REQUIRE(osmium::detail::str_to_int("-100") == 0); REQUIRE(osmium::detail::str_to_int("1 ") == 0); REQUIRE(osmium::detail::str_to_int("x1") == 0); REQUIRE(osmium::detail::str_to_int("1x") == 0); REQUIRE(osmium::detail::str_to_int("2 3") == 0); REQUIRE(osmium::detail::str_to_int("9999999999999999999999") == 0); } TEST_CASE("string to integer conversion") { test_conv(); test_conv(); test_conv(); REQUIRE(osmium::detail::str_to_int("126") == 126); REQUIRE(osmium::detail::str_to_int("127") == 0); REQUIRE(osmium::detail::str_to_int("128") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("254") == 254); REQUIRE(osmium::detail::str_to_int("255") == 0); REQUIRE(osmium::detail::str_to_int("256") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("32766") == 32766); REQUIRE(osmium::detail::str_to_int("32767") == 0); REQUIRE(osmium::detail::str_to_int("32768") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("65534") == 65534); REQUIRE(osmium::detail::str_to_int("65535") == 0); REQUIRE(osmium::detail::str_to_int("65536") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("2147483646") == 2147483646ll); REQUIRE(osmium::detail::str_to_int("2147483647") == 0); REQUIRE(osmium::detail::str_to_int("2147483648") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("4294967294") == 4294967294ull); REQUIRE(osmium::detail::str_to_int("4294967295") == 0); REQUIRE(osmium::detail::str_to_int("4294967296") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("9223372036854775806") == 9223372036854775806ll); REQUIRE(osmium::detail::str_to_int("9223372036854775807") == 0); REQUIRE(osmium::detail::str_to_int("9223372036854775808") == 0); test_conv(); REQUIRE(osmium::detail::str_to_int("9223372036854775806") == 9223372036854775806ull); REQUIRE(osmium::detail::str_to_int("9223372036854775807") == 0); REQUIRE(osmium::detail::str_to_int("9223372036854775808") == 0); }