1 #include "catch.hpp" 2 3 #include "test_crc.hpp" 4 5 #include <osmium/builder/attr.hpp> 6 #include <osmium/osm/area.hpp> 7 #include <osmium/osm/crc.hpp> 8 9 #include <string> 10 11 using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace) 12 13 TEST_CASE("Build area") { 14 osmium::memory::Buffer buffer(10000); 15 16 osmium::builder::add_area(buffer, 17 _id(17), 18 _version(3), 19 _visible(), 20 _cid(333), 21 _uid(21), 22 _timestamp(time_t(123)), 23 _user("foo"), 24 _tag("landuse", "forest"), 25 _tag("name", "Sherwood Forest"), 26 _outer_ring({ 27 {1, {3.2, 4.2}}, 28 {2, {3.5, 4.7}}, 29 {3, {3.6, 4.9}}, 30 {1, {3.2, 4.2}} 31 }), 32 _inner_ring({ 33 {5, {1.0, 1.0}}, 34 {6, {8.0, 1.0}}, 35 {7, {8.0, 8.0}}, 36 {8, {1.0, 8.0}}, 37 {5, {1.0, 1.0}} 38 }) 39 ); 40 41 const osmium::Area& area = buffer.get<osmium::Area>(0); 42 43 REQUIRE(17 == area.id()); 44 REQUIRE(3 == area.version()); 45 REQUIRE(area.visible()); 46 REQUIRE(333 == area.changeset()); 47 REQUIRE(21 == area.uid()); 48 REQUIRE(std::string("foo") == area.user()); 49 REQUIRE(123 == uint32_t(area.timestamp())); 50 REQUIRE(2 == area.tags().size()); 51 52 int inner = 0; 53 int outer = 0; 54 for (const auto& subitem : area) { 55 switch (subitem.type()) { 56 case osmium::item_type::outer_ring: { 57 const auto& ring = static_cast<const osmium::OuterRing&>(subitem); 58 REQUIRE(ring.size() == 4); 59 ++outer; 60 } 61 break; 62 case osmium::item_type::inner_ring: { 63 const auto& ring = static_cast<const osmium::OuterRing&>(subitem); 64 REQUIRE(ring.size() == 5); 65 ++inner; 66 } 67 break; 68 default: 69 break; 70 } 71 } 72 73 REQUIRE(outer == 1); 74 REQUIRE(inner == 1); 75 76 osmium::CRC<crc_type> crc32; 77 crc32.update(area); 78 REQUIRE(crc32().checksum() == 0x2b2b7fa0); 79 80 const osmium::Box envelope = area.envelope(); 81 REQUIRE(envelope.bottom_left().lon() == Approx(3.2)); 82 REQUIRE(envelope.bottom_left().lat() == Approx(4.2)); 83 REQUIRE(envelope.top_right().lon() == Approx(3.6)); 84 REQUIRE(envelope.top_right().lat() == Approx(4.9)); 85 } 86 87