File: test_object_pointer_collection.cpp

package info (click to toggle)
libosmium 2.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,544 kB
  • sloc: cpp: 52,804; sh: 148; makefile: 19
file content (84 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download | duplicates (6)
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
#include "catch.hpp"

#include <osmium/builder/attr.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/object_pointer_collection.hpp>
#include <osmium/osm/object_comparisons.hpp>
#include <osmium/visitor.hpp>

using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)

TEST_CASE("Create ObjectPointerCollection") {
    osmium::memory::Buffer buffer{1024, osmium::memory::Buffer::auto_grow::yes};

    osmium::builder::add_node(buffer,
        _id(3),
        _version(3)
    );

    osmium::builder::add_node(buffer,
        _id(1),
        _version(2)
    );

    osmium::builder::add_node(buffer,
        _id(1),
        _version(4)
    );

    osmium::ObjectPointerCollection collection;
    REQUIRE(collection.empty());
    REQUIRE(collection.size() == 0); // NOLINT(readability-container-size-empty)

    osmium::apply(buffer, collection);

    REQUIRE_FALSE(collection.empty());
    REQUIRE(collection.size() == 3);

    auto it = collection.cbegin();
    REQUIRE(it->id() == 3);
    REQUIRE(it->version() == 3);
    ++it;
    REQUIRE(it->id() == 1);
    REQUIRE(it->version() == 2);
    ++it;
    REQUIRE(it->id() == 1);
    REQUIRE(it->version() == 4);
    ++it;
    REQUIRE(it == collection.cend());

    collection.sort(osmium::object_order_type_id_version{});

    REQUIRE(collection.size() == 3);

    it = collection.cbegin();
    REQUIRE(it->id() == 1);
    REQUIRE(it->version() == 2);
    ++it;
    REQUIRE(it->id() == 1);
    REQUIRE(it->version() == 4);
    ++it;
    REQUIRE(it->id() == 3);
    REQUIRE(it->version() == 3);
    ++it;
    REQUIRE(it == collection.cend());

    collection.sort(osmium::object_order_type_id_reverse_version{});

    it = collection.cbegin();
    REQUIRE(it->id() == 1);
    REQUIRE(it->version() == 4);
    ++it;
    REQUIRE(it->id() == 1);
    REQUIRE(it->version() == 2);
    ++it;
    REQUIRE(it->id() == 3);
    REQUIRE(it->version() == 3);
    ++it;
    REQUIRE(it == collection.cend());

    collection.clear();

    REQUIRE(collection.empty());
}