Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/protozero/basic_pbf_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace protozero {
template <typename TBuffer, typename T>
class basic_pbf_builder : public basic_pbf_writer<TBuffer> {

static_assert(std::is_same<pbf_tag_type, typename std::underlying_type<T>::type>::value,
static_assert(std::is_same<pbf_tag_type, std::underlying_type_t<T>>::value,
"T must be enum with underlying type protozero::pbf_tag_type");

public:
Expand Down
2 changes: 1 addition & 1 deletion include/protozero/pbf_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace protozero {
template <typename T>
class pbf_message : public pbf_reader {

static_assert(std::is_same<pbf_tag_type, typename std::underlying_type<T>::type>::value,
static_assert(std::is_same<pbf_tag_type, std::underlying_type_t<T>>::value,
"T must be enum with underlying type protozero::pbf_tag_type");

public:
Expand Down
6 changes: 5 additions & 1 deletion test/t/complex/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,9 @@ TEST_CASE("write complex data using pbf_builder: all") {
REQUIRE(number_of_u == 5);
}

static void check_message(const std::string& buffer) {
namespace {

void check_message(const std::string& buffer) {
protozero::pbf_reader item{buffer};

while (item.next()) {
Expand All @@ -640,6 +642,8 @@ static void check_message(const std::string& buffer) {
}
}

} // anonymous namespace

TEST_CASE("write complex with subwriter using pbf_writer") {
std::string buffer_test;
protozero::pbf_writer pbf_test{buffer_test};
Expand Down
12 changes: 8 additions & 4 deletions test/t/nested/reader_test_cases.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

#include <test.hpp>

inline void check_subsub(protozero::pbf_reader message) {
namespace {

void check_subsub(protozero::pbf_reader message) {
while (message.next()) {
switch (message.tag()) {
case 1: {
Expand All @@ -20,7 +22,7 @@ inline void check_subsub(protozero::pbf_reader message) {
}
}

inline void check_sub(protozero::pbf_reader message) {
void check_sub(protozero::pbf_reader message) {
while (message.next()) {
switch (message.tag()) {
case 1: {
Expand All @@ -39,7 +41,7 @@ inline void check_sub(protozero::pbf_reader message) {
}
}

inline void check(protozero::pbf_reader message) {
void check(protozero::pbf_reader message) {
while (message.next()) {
switch (message.tag()) {
case 1: {
Expand All @@ -58,7 +60,7 @@ inline void check(protozero::pbf_reader message) {
}
}

inline void check_empty(protozero::pbf_reader message) {
void check_empty(protozero::pbf_reader message) {
while (message.next()) {
switch (message.tag()) {
case 1: {
Expand All @@ -77,6 +79,8 @@ inline void check_empty(protozero::pbf_reader message) {
}
}

} // anonymous namespace

TEST_CASE("read nested message fields: string") {
const std::string buffer = load_data("nested/data-message");

Expand Down
8 changes: 6 additions & 2 deletions test/t/tag_and_type/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

#include <test.hpp>

namespace {

enum class ExampleMsg : protozero::pbf_tag_type {
repeated_uint32_x = 1
};

inline std::vector<uint32_t> read_data(const std::string& data) {
std::vector<uint32_t> read_data(const std::string& data) {
std::vector<uint32_t> values;

protozero::pbf_message<ExampleMsg> message{data};
Expand All @@ -35,7 +37,7 @@ inline std::vector<uint32_t> read_data(const std::string& data) {
return values;
}

inline std::vector<uint32_t> read_data_packed(const std::string& data) {
std::vector<uint32_t> read_data_packed(const std::string& data) {
std::vector<uint32_t> values;

protozero::pbf_message<ExampleMsg> message{data};
Expand All @@ -47,6 +49,8 @@ inline std::vector<uint32_t> read_data_packed(const std::string& data) {
return values;
}

} // anonymous namespace

TEST_CASE("read not packed repeated field with tag_and_type") {
const auto values = read_data(load_data("tag_and_type/data-not-packed"));

Expand Down
6 changes: 5 additions & 1 deletion test/t/tags/reader_test_cases.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

#include <test.hpp>

inline void check_tag(const std::string& buffer, protozero::pbf_tag_type tag) {
namespace {

void check_tag(const std::string& buffer, protozero::pbf_tag_type tag) {
protozero::pbf_reader item{buffer};

REQUIRE(item.next());
Expand All @@ -10,6 +12,8 @@ inline void check_tag(const std::string& buffer, protozero::pbf_tag_type tag) {
REQUIRE_FALSE(item.next());
}

} // anonymous namespace

TEST_CASE("read tag: 1") {
check_tag(load_data("tags/data-tag-1"), 1UL);
}
Expand Down
6 changes: 5 additions & 1 deletion test/t/vector_tile/reader_test_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
#include <string>
#include <vector>

namespace {

// Input data.vector is encoded according to
// https://github.com/mapbox/mapnik-vector-tile/blob/master/proto/vector_tile.proto

static std::string get_name(protozero::pbf_reader layer) { // copy!
std::string get_name(protozero::pbf_reader layer) { // copy!
while (layer.next(1)) { // required string name
return layer.get_string();
}
REQUIRE(false); // should never be here
return "";
}

} // anonymous namespace

TEST_CASE("reading vector tiles") {
static const std::vector<std::string> expected_layer_names = {
"landuse", "waterway", "water", "aeroway", "barrier_line", "building",
Expand Down
8 changes: 6 additions & 2 deletions test/unit/test_endian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@

#include <protozero/byteswap.hpp>

static int32_t check_swap_4(int32_t data) noexcept {
namespace {

int32_t check_swap_4(int32_t data) noexcept {
protozero::byteswap_inplace(&data);
protozero::byteswap_inplace(&data);
return data;
}

static int64_t check_swap_8(int64_t data) noexcept {
int64_t check_swap_8(int64_t data) noexcept {
protozero::byteswap_inplace(&data);
protozero::byteswap_inplace(&data);
return data;
}

} // anonymous namespace

TEST_CASE("byte swapping") {
REQUIRE(0 == check_swap_4(0));
REQUIRE(1 == check_swap_4(1));
Expand Down
8 changes: 6 additions & 2 deletions test/unit/test_zigzag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ static_assert(protozero::decode_zigzag64(0xfffffffffffffffdULL) == -0x7fffffffff
static_assert(protozero::decode_zigzag64(2 * static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) ) == std::numeric_limits<int64_t>::max(), "test constexpr zigzag functions");
static_assert(protozero::decode_zigzag64(2 * static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) - 1) == -std::numeric_limits<int64_t>::max(), "test constexpr zigzag functions");

inline constexpr int32_t zz32(int32_t val) noexcept {
namespace {

constexpr int32_t zz32(int32_t val) noexcept {
return protozero::decode_zigzag32(protozero::encode_zigzag32(val));
}

inline constexpr int64_t zz64(int64_t val) noexcept {
constexpr int64_t zz64(int64_t val) noexcept {
return protozero::decode_zigzag64(protozero::encode_zigzag64(val));
}

} // anonymous namespace

TEST_CASE("zigzag encode some 32 bit values") {
REQUIRE(protozero::encode_zigzag32( 0L) == 0UL);
REQUIRE(protozero::encode_zigzag32(-1L) == 1UL);
Expand Down
4 changes: 4 additions & 0 deletions tools/pbf-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Call with --help/-h to see more options.
#include <stdexcept>
#include <string>

namespace {

std::string decode(const char* data, std::size_t len, const std::string& indent);

// Try decoding as a nested message
Expand Down Expand Up @@ -203,6 +205,8 @@ std::string read_from_stdin() {
std::istreambuf_iterator<char>()};
}

} // anonymous namespace

int main(int argc, char* argv[]) {
static struct option long_options[] = {
{"help", no_argument, nullptr, 'h'},
Expand Down
Loading