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-2021 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 "input.hpp"
13 
14 TEST_CASE("it's good if input data is ordered", "[NoDB]")
15 {
16     type_id const tiv1{osmium::item_type::node, 1};
17     type_id const tiv2{osmium::item_type::node, 2};
18     type_id const tiv3{osmium::item_type::way, 1};
19     type_id const tiv4{osmium::item_type::way, 2};
20     type_id const tiv5{osmium::item_type::relation, 1};
21     type_id const tiv6{osmium::item_type::relation, 2};
22 
23     REQUIRE_NOTHROW(check_input(tiv1, tiv2));
24     REQUIRE_NOTHROW(check_input(tiv2, tiv3));
25     REQUIRE_NOTHROW(check_input(tiv3, tiv4));
26     REQUIRE_NOTHROW(check_input(tiv4, tiv5));
27     REQUIRE_NOTHROW(check_input(tiv5, tiv6));
28 }
29 
30 TEST_CASE("negative OSM object ids are not allowed", "[NoDB]")
31 {
32     type_id const tivn{osmium::item_type::node, -17};
33     type_id const tivw{osmium::item_type::way, -1};
34     type_id const tivr{osmium::item_type::relation, -999};
35 
36     REQUIRE_THROWS_WITH(
37         check_input(tivn, tivn),
38         "Negative OSM object ids are not allowed: node id -17.");
39     REQUIRE_THROWS_WITH(check_input(tivw, tivw),
40                         "Negative OSM object ids are not allowed: way id -1.");
41     REQUIRE_THROWS_WITH(
42         check_input(tivr, tivr),
43         "Negative OSM object ids are not allowed: relation id -999.");
44 }
45 
46 TEST_CASE("objects of the same type must be ordered", "[NoDB]")
47 {
48     type_id const tiv1{osmium::item_type::node, 42};
49     type_id const tiv2{osmium::item_type::node, 3};
50 
51     REQUIRE_THROWS_WITH(check_input(tiv1, tiv2),
52                         "Input data is not ordered: node id 3 after 42.");
53 }
54 
55 TEST_CASE("a node after a way or relation is not allowed", "[NoDB]")
56 {
57     type_id const tiv1w{osmium::item_type::way, 42};
58     type_id const tiv1r{osmium::item_type::relation, 42};
59     type_id const tiv2{osmium::item_type::node, 100};
60 
61     REQUIRE_THROWS_WITH(check_input(tiv1w, tiv2),
62                         "Input data is not ordered: node after way.");
63     REQUIRE_THROWS_WITH(check_input(tiv1r, tiv2),
64                         "Input data is not ordered: node after relation.");
65 }
66 
67 TEST_CASE("a way after a relation is not allowed", "[NoDB]")
68 {
69     type_id const tiv1{osmium::item_type::relation, 42};
70     type_id const tiv2{osmium::item_type::way, 100};
71 
72     REQUIRE_THROWS_WITH(check_input(tiv1, tiv2),
73                         "Input data is not ordered: way after relation.");
74 }
75 
76 TEST_CASE("no object may appear twice", "[NoDB]")
77 {
78     type_id const tiv1{osmium::item_type::way, 42};
79     type_id const tiv2{osmium::item_type::way, 42};
80 
81     REQUIRE_THROWS_WITH(
82         check_input(tiv1, tiv2),
83         "Input data is not ordered: way id 42 appears more than once.");
84 }
85 
86