-
-
Notifications
You must be signed in to change notification settings - Fork 477
/
Copy pathtest-params.cpp
65 lines (54 loc) · 1.88 KB
/
test-params.cpp
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
56
57
58
59
60
61
62
63
64
65
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2025 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include <catch.hpp>
#include "params.hpp"
TEST_CASE("Set param value", "[NoDB]")
{
param_value_t const p_null{null_param_t()};
param_value_t const p_str{std::string{"foo"}};
param_value_t const p_int{static_cast<int64_t>(26)};
param_value_t const p_double{3.141};
param_value_t const p_true{true};
param_value_t const p_false{false};
REQUIRE(to_string(p_null).empty());
REQUIRE(to_string(p_str) == "foo");
REQUIRE(to_string(p_int) == "26");
REQUIRE(to_string(p_double) == "3.141");
REQUIRE(to_string(p_true) == "true");
REQUIRE(to_string(p_false) == "false");
}
TEST_CASE("Params with different value types", "[NoDB]")
{
params_t params;
REQUIRE_FALSE(params.has("foo"));
params.set("foo", 99);
REQUIRE(params.has("foo"));
REQUIRE(params.get("foo") == param_value_t(static_cast<int64_t>(99)));
REQUIRE(params.get_int64("foo") == 99);
params.set("foo", "astring");
REQUIRE(params.has("foo"));
REQUIRE(params.get("foo") == param_value_t(std::string("astring")));
REQUIRE(params.get_string("foo") == "astring");
REQUIRE_THROWS(params.get_int64("foo"));
}
TEST_CASE("Set params with explicit type", "[NoDB]")
{
params_t params;
params.set("isstring", "hi");
params.set("isint", 567);
params.set("isdouble", 567.0);
params.set("istrue", true);
params.set("isfalse", false);
REQUIRE(params.get_string("isstring") == "hi");
REQUIRE(params.get_int64("isint") == 567);
REQUIRE(params.get_double("isdouble") == Approx(567.0));
REQUIRE(params.get_bool("istrue"));
REQUIRE_FALSE(params.get_bool("isfalse"));
REQUIRE_THROWS(params.get("does not exist"));
}