|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | + * |
| 4 | + * This file is part of osm2pgsql (https://osm2pgsql.org/). |
| 5 | + * |
| 6 | + * Copyright (C) 2006-2024 by the osm2pgsql developer community. |
| 7 | + * For a full list of authors see the git log. |
| 8 | + */ |
| 9 | + |
| 10 | +#include <catch.hpp> |
| 11 | + |
| 12 | +#include "params.hpp" |
| 13 | + |
| 14 | +TEST_CASE("Set param value", "[NoDB]") |
| 15 | +{ |
| 16 | + param_value_t const p_null{null_param_t()}; |
| 17 | + param_value_t const p_str{"foo"}; |
| 18 | + param_value_t const p_int{26}; |
| 19 | + param_value_t const p_double{3.141}; |
| 20 | + param_value_t const p_true{true}; |
| 21 | + param_value_t const p_false{false}; |
| 22 | + |
| 23 | + REQUIRE(to_string(p_null).empty()); |
| 24 | + REQUIRE(to_string(p_str) == "foo"); |
| 25 | + REQUIRE(to_string(p_int) == "26"); |
| 26 | + REQUIRE(to_string(p_double) == "3.141"); |
| 27 | + REQUIRE(to_string(p_true) == "true"); |
| 28 | + REQUIRE(to_string(p_false) == "false"); |
| 29 | +} |
| 30 | + |
| 31 | +TEST_CASE("Params with different value types", "[NoDB]") |
| 32 | +{ |
| 33 | + params_t params; |
| 34 | + REQUIRE_FALSE(params.has("foo")); |
| 35 | + |
| 36 | + params.set("foo", 99); |
| 37 | + REQUIRE(params.has("foo")); |
| 38 | + REQUIRE(params.get("foo") == param_value_t(99)); |
| 39 | + REQUIRE(params.get_int64("foo") == 99); |
| 40 | + |
| 41 | + params.set("foo", "astring"); |
| 42 | + REQUIRE(params.has("foo")); |
| 43 | + REQUIRE(params.get("foo") == param_value_t("astring")); |
| 44 | + REQUIRE(params.get_string("foo") == "astring"); |
| 45 | + REQUIRE_THROWS(params.get_int64("foo")); |
| 46 | +} |
| 47 | + |
| 48 | +TEST_CASE("Set params with explicit type", "[NoDB]") |
| 49 | +{ |
| 50 | + params_t params; |
| 51 | + |
| 52 | + params.set_null("isnull"); |
| 53 | + params.set_string("isstring", "hi"); |
| 54 | + params.set_int64("isint", 567); |
| 55 | + params.set_double("isdouble", 567); |
| 56 | + params.set_bool("istrue", true); |
| 57 | + params.set_bool("isfalse", false); |
| 58 | + |
| 59 | + REQUIRE(params.get("isnull") == param_value_t()); |
| 60 | + REQUIRE(params.get_string("isstring") == "hi"); |
| 61 | + REQUIRE(params.get_int64("isint") == 567); |
| 62 | + REQUIRE(params.get_double("isdouble") == Approx(567.0)); |
| 63 | + REQUIRE(params.get_bool("istrue")); |
| 64 | + REQUIRE_FALSE(params.get_bool("isfalse")); |
| 65 | +} |
0 commit comments