File: test-check-input.cpp

package info (click to toggle)
osm2pgsql 1.4.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,124 kB
  • sloc: cpp: 41,466; ansic: 1,366; python: 564; sh: 19; makefile: 15
file content (87 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * This file is part of osm2pgsql (https://osm2pgsql.org/).
 *
 * Copyright (C) 2006-2021 by the osm2pgsql developer community.
 * For a full list of authors see the git log.
 */

#include <catch.hpp>

#include "input.hpp"

TEST_CASE("it's good if input data is ordered", "[NoDB]")
{
    type_id_version const tiv1{osmium::item_type::node, 1, 1};
    type_id_version const tiv2{osmium::item_type::node, 1, 2};
    type_id_version const tiv3{osmium::item_type::node, 2, 1};
    type_id_version const tiv4{osmium::item_type::way, 1, 1};
    type_id_version const tiv5{osmium::item_type::way, 2, 1};
    type_id_version const tiv6{osmium::item_type::relation, 1, 1};
    type_id_version const tiv7{osmium::item_type::relation, 1, 2};

    REQUIRE_NOTHROW(check_input(tiv1, tiv2));
    REQUIRE_NOTHROW(check_input(tiv2, tiv3));
    REQUIRE_NOTHROW(check_input(tiv3, tiv4));
    REQUIRE_NOTHROW(check_input(tiv4, tiv5));
    REQUIRE_NOTHROW(check_input(tiv5, tiv6));
    REQUIRE_NOTHROW(check_input(tiv6, tiv7));
}

TEST_CASE("negative OSM object ids are not allowed", "[NoDB]")
{
    type_id_version const tivn{osmium::item_type::node, -17, 1};
    type_id_version const tivw{osmium::item_type::way, -1, 1};
    type_id_version const tivr{osmium::item_type::relation, -999, 17};

    REQUIRE_THROWS_WITH(
        check_input(tivn, tivn),
        "Negative OSM object ids are not allowed: node id -17.");
    REQUIRE_THROWS_WITH(check_input(tivw, tivw),
                        "Negative OSM object ids are not allowed: way id -1.");
    REQUIRE_THROWS_WITH(
        check_input(tivr, tivr),
        "Negative OSM object ids are not allowed: relation id -999.");
}

TEST_CASE("objects of the same type must be ordered", "[NoDB]")
{
    type_id_version const tiv1{osmium::item_type::node, 42, 1};
    type_id_version const tiv2{osmium::item_type::node, 3, 1};

    REQUIRE_THROWS_WITH(check_input(tiv1, tiv2),
                        "Input data is not ordered: node id 3 after 42.");
}

TEST_CASE("a node after a way or relation is not allowed", "[NoDB]")
{
    type_id_version const tiv1w{osmium::item_type::way, 42, 1};
    type_id_version const tiv1r{osmium::item_type::relation, 42, 1};
    type_id_version const tiv2{osmium::item_type::node, 100, 1};

    REQUIRE_THROWS_WITH(check_input(tiv1w, tiv2),
                        "Input data is not ordered: node after way.");
    REQUIRE_THROWS_WITH(check_input(tiv1r, tiv2),
                        "Input data is not ordered: node after relation.");
}

TEST_CASE("a way after a relation is not allowed", "[NoDB]")
{
    type_id_version const tiv1{osmium::item_type::relation, 42, 1};
    type_id_version const tiv2{osmium::item_type::way, 100, 1};

    REQUIRE_THROWS_WITH(check_input(tiv1, tiv2),
                        "Input data is not ordered: way after relation.");
}

TEST_CASE("versions must be ordered", "[NoDB]")
{
    type_id_version const tiv1{osmium::item_type::way, 42, 2};
    type_id_version const tiv2{osmium::item_type::way, 42, 1};

    REQUIRE_THROWS_WITH(
        check_input(tiv1, tiv2),
        "Input data is not ordered: way id 42 version 1 after 2.");
}