Updated bundled protozero to v1.7.0
This commit is contained in:
+15233
-9213
File diff suppressed because it is too large
Load Diff
@@ -8,9 +8,16 @@
|
||||
# If called without a test case it will iterate over all test cases generating
|
||||
# all data.
|
||||
#
|
||||
# This program should be called with the "test" directory as current directory.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$CXX" ]; then
|
||||
echo "Please set CXX before running this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
for dir in t/*; do
|
||||
$0 $dir
|
||||
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
#ifndef BUFFER_HPP
|
||||
#define BUFFER_HPP
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
#include <protozero/buffer_fixed.hpp>
|
||||
#include <protozero/buffer_string.hpp>
|
||||
#include <protozero/buffer_vector.hpp>
|
||||
|
||||
// This "simulates" an externally defined buffer type to make sure our
|
||||
// buffer adaptor functions do the right thing.
|
||||
namespace test_external {
|
||||
class ext_buffer : public std::string {
|
||||
};
|
||||
} // namespace test_external
|
||||
|
||||
namespace protozero {
|
||||
|
||||
template <>
|
||||
struct buffer_customization<test_external::ext_buffer> {
|
||||
|
||||
static std::size_t size(const test_external::ext_buffer* buffer) noexcept {
|
||||
return buffer->size();
|
||||
}
|
||||
|
||||
static void append(test_external::ext_buffer* buffer, const char* data, std::size_t count) {
|
||||
buffer->append(data, count);
|
||||
}
|
||||
|
||||
static void append_zeros(test_external::ext_buffer* buffer, std::size_t count) {
|
||||
buffer->append(count, '\0');
|
||||
}
|
||||
|
||||
static void resize(test_external::ext_buffer* buffer, std::size_t size) {
|
||||
protozero_assert(size < buffer->size());
|
||||
buffer->resize(size);
|
||||
}
|
||||
|
||||
static void reserve_additional(test_external::ext_buffer* buffer, std::size_t size) {
|
||||
buffer->reserve(buffer->size() + size);
|
||||
}
|
||||
|
||||
static void erase_range(test_external::ext_buffer* buffer, std::size_t from, std::size_t to) {
|
||||
protozero_assert(from <= buffer->size());
|
||||
protozero_assert(to <= buffer->size());
|
||||
protozero_assert(from <= to);
|
||||
buffer->erase(std::next(buffer->begin(), from), std::next(buffer->begin(), to));
|
||||
}
|
||||
|
||||
static char* at_pos(test_external::ext_buffer* buffer, std::size_t pos) {
|
||||
protozero_assert(pos <= buffer->size());
|
||||
return (&*buffer->begin()) + pos;
|
||||
}
|
||||
|
||||
static void push_back(test_external::ext_buffer* buffer, char ch) {
|
||||
buffer->push_back(ch);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace protozero
|
||||
|
||||
// The following structs are used in many tests using TEMPLATE_TEST_CASE() to
|
||||
// test the different buffer types:
|
||||
//
|
||||
// 1. Dynamically sized buffer based on std::string.
|
||||
// 2. Dynamically sized buffer based on std::vector<char>.
|
||||
// 3. Statically sized buffer based on std::array<char, N>.
|
||||
// 4. Externally defined buffer.
|
||||
|
||||
class buffer_test_string {
|
||||
|
||||
std::string m_buffer;
|
||||
|
||||
public:
|
||||
|
||||
using type = std::string;
|
||||
using writer_type = protozero::pbf_writer; // == protozero::basic_pbf_writer<type>;
|
||||
|
||||
type& buffer() noexcept {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
const char *data() const noexcept {
|
||||
return m_buffer.data();
|
||||
}
|
||||
|
||||
std::size_t size() const noexcept {
|
||||
return m_buffer.size();
|
||||
}
|
||||
}; // class buffer_test_string
|
||||
|
||||
class buffer_test_vector {
|
||||
|
||||
std::vector<char> m_buffer;
|
||||
|
||||
public:
|
||||
|
||||
using type = std::vector<char>;
|
||||
using writer_type = protozero::basic_pbf_writer<type>;
|
||||
|
||||
type& buffer() noexcept {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
const char *data() const noexcept {
|
||||
return m_buffer.data();
|
||||
}
|
||||
|
||||
std::size_t size() const noexcept {
|
||||
return m_buffer.size();
|
||||
}
|
||||
}; // class buffer_test_vector
|
||||
|
||||
class buffer_test_array {
|
||||
|
||||
public:
|
||||
using type = protozero::fixed_size_buffer_adaptor;
|
||||
using writer_type = protozero::basic_pbf_writer<type>;
|
||||
|
||||
type& buffer() noexcept {
|
||||
return adaptor;
|
||||
}
|
||||
|
||||
const char *data() const noexcept {
|
||||
return adaptor.data();
|
||||
}
|
||||
|
||||
std::size_t size() const noexcept {
|
||||
return adaptor.size();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::array<char, 1024> m_buffer = {{0}};
|
||||
type adaptor{m_buffer};
|
||||
|
||||
}; // class buffer_test_array
|
||||
|
||||
class buffer_test_external {
|
||||
|
||||
test_external::ext_buffer m_buffer;
|
||||
|
||||
public:
|
||||
|
||||
using type = test_external::ext_buffer;
|
||||
using writer_type = protozero::basic_pbf_writer<type>;
|
||||
|
||||
type& buffer() noexcept {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
const char *data() const noexcept {
|
||||
return m_buffer.data();
|
||||
}
|
||||
|
||||
std::size_t size() const noexcept {
|
||||
return m_buffer.size();
|
||||
}
|
||||
}; // class buffer_test_external
|
||||
|
||||
#endif // BUFFER_HPP
|
||||
+18
-9
@@ -1,5 +1,8 @@
|
||||
// NOLINT(llvm-header-guard)
|
||||
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
|
||||
#define PBF_TYPE_NAME PROTOZERO_TEST_STRING(PBF_TYPE)
|
||||
#define GET_TYPE PROTOZERO_TEST_CONCAT(get_packed_, PBF_TYPE)
|
||||
#define ADD_TYPE PROTOZERO_TEST_CONCAT(add_packed_, PBF_TYPE)
|
||||
@@ -92,7 +95,7 @@ TEST_CASE("read repeated packed field: " PBF_TYPE_NAME) {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.GET_TYPE(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.GET_TYPE(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,21 +108,27 @@ TEST_CASE("write repeated packed field: " PBF_TYPE_NAME) {
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
cpp_type data[] = { 17 };
|
||||
std::array<cpp_type, 1> data = {{ 17 }};
|
||||
pw.ADD_TYPE(1, std::begin(data), std::begin(data) /* !!!! */);
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
cpp_type data[] = { 17 };
|
||||
std::array<cpp_type, 1> data = {{ 17 }};
|
||||
pw.ADD_TYPE(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-one"));
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
cpp_type data[] = {
|
||||
std::array<cpp_type,
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
8
|
||||
#else
|
||||
5
|
||||
#endif
|
||||
> data = {{
|
||||
17
|
||||
, 200
|
||||
, 0
|
||||
@@ -130,7 +139,7 @@ TEST_CASE("write repeated packed field: " PBF_TYPE_NAME) {
|
||||
, -1
|
||||
,std::numeric_limits<cpp_type>::min()
|
||||
#endif
|
||||
};
|
||||
}};
|
||||
pw.ADD_TYPE(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-many"));
|
||||
@@ -246,9 +255,9 @@ TEST_CASE("write from different types of iterators: " PBF_TYPE_NAME) {
|
||||
|
||||
SECTION("from uint16_t") {
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
const int16_t data[] = { 1, 4, 9, 16, 25 };
|
||||
const std::array< int16_t, 5> data = {{ 1, 4, 9, 16, 25 }};
|
||||
#else
|
||||
const uint16_t data[] = { 1, 4, 9, 16, 25 };
|
||||
const std::array<uint16_t, 5> data = {{ 1, 4, 9, 16, 25 }};
|
||||
#endif
|
||||
|
||||
pw.ADD_TYPE(1, std::begin(data), std::end(data));
|
||||
@@ -290,7 +299,7 @@ TEST_CASE("write from different types of iterators: " PBF_TYPE_NAME) {
|
||||
REQUIRE(std::distance(it_range.begin(), it_range.end()) == 0);
|
||||
REQUIRE(it_range.size() == 0); // NOLINT(readability-container-size-empty)
|
||||
|
||||
REQUIRE_THROWS_AS(it_range.front(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(it_range.drop_front(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(it_range.front(), assert_error);
|
||||
REQUIRE_THROWS_AS(it_range.drop_front(), assert_error);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ TEST_CASE("read field: " PBF_TYPE_NAME) {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.GET_TYPE(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.GET_TYPE(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include <stdexcept>
|
||||
// Define protozero_assert() to throw this error. This allows the tests to
|
||||
// check that the assert fails.
|
||||
|
||||
+2
@@ -1,5 +1,7 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ TEST_CASE("check alignment issues for fixed32 field") {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ TEST_CASE("check alignment issues for fixed32 field") {
|
||||
abuffer.append(load_data("fixed32/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), assert_error);
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed32() == 0UL);
|
||||
REQUIRE_THROWS(item.get_fixed32());
|
||||
@@ -66,7 +66,7 @@ TEST_CASE("check alignment issues for fixed32 field") {
|
||||
abuffer.append(load_data("fixed32/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE_THROWS_AS(item.skip(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.skip(), assert_error);
|
||||
REQUIRE(item.next());
|
||||
item.skip();
|
||||
REQUIRE_THROWS(item.skip());
|
||||
@@ -114,7 +114,7 @@ TEST_CASE("check alignment issues for fixed64 field") {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ TEST_CASE("write bool field using moved pbf_builder") {
|
||||
|
||||
protozero::pbf_builder<TestBoolean::Test> pw{std::move(pw2)};
|
||||
REQUIRE(pw.valid());
|
||||
REQUIRE_FALSE(pw2.valid()); // NOLINT(hicpp-invalid-access-moved, bugprone-use-after-move)
|
||||
REQUIRE_FALSE(pw2.valid()); // NOLINT(hicpp-invalid-access-moved, bugprone-use-after-move, clang-analyzer-cplusplus.Move)
|
||||
|
||||
SECTION("false") {
|
||||
pw.add_bool(TestBoolean::Test::required_bool_b, false);
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestBoolean::Test msg;
|
||||
|
||||
msg.set_b(0);
|
||||
|
||||
+7
-6
@@ -1,21 +1,22 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <test.hpp> // IWYU pragma: keep
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/bool/bool_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write bool field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write bool field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestBoolean::Test msg;
|
||||
|
||||
SECTION("false") {
|
||||
pw.add_bool(1, false);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE_FALSE(msg.b());
|
||||
}
|
||||
@@ -23,7 +24,7 @@ TEST_CASE("write bool field and check with libprotobuf") {
|
||||
SECTION("true") {
|
||||
pw.add_bool(1, true);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.b());
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST_CASE("read bytes field: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_bytes(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_bytes(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestBytes::Test msg;
|
||||
|
||||
msg.set_s("");
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/bytes/bytes_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write bytes field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write bytes field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestBytes::Test msg;
|
||||
|
||||
SECTION("empty") {
|
||||
pw.add_string(1, "");
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s().empty());
|
||||
}
|
||||
@@ -21,7 +22,7 @@ TEST_CASE("write bytes field and check with libprotobuf") {
|
||||
SECTION("one") {
|
||||
pw.add_string(1, "x");
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s() == "x");
|
||||
}
|
||||
@@ -29,7 +30,7 @@ TEST_CASE("write bytes field and check with libprotobuf") {
|
||||
SECTION("string") {
|
||||
pw.add_string(1, "foobar");
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s() == "foobar");
|
||||
}
|
||||
@@ -42,7 +43,7 @@ TEST_CASE("write bytes field and check with libprotobuf") {
|
||||
|
||||
pw.add_string(1, data);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s().size() == 3);
|
||||
REQUIRE(msg.s()[1] == char(2));
|
||||
|
||||
+86
-30
@@ -1,6 +1,12 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <protozero/buffer_fixed.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
|
||||
namespace TestComplex {
|
||||
|
||||
enum class Test : protozero::pbf_tag_type {
|
||||
@@ -120,11 +126,7 @@ TEST_CASE("read complex data using pbf_reader: all") {
|
||||
}
|
||||
case 7: {
|
||||
const auto pi = item.get_packed_sint32();
|
||||
int32_t sum = 0;
|
||||
for (auto val : pi) {
|
||||
sum += val;
|
||||
}
|
||||
REQUIRE(sum == 5);
|
||||
REQUIRE(std::accumulate(pi.cbegin(), pi.cend(), 0) == 5);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
@@ -265,11 +267,7 @@ TEST_CASE("read complex data using pbf_message: all") {
|
||||
}
|
||||
case TestComplex::Test::packed_sint32_d: {
|
||||
const auto pi = item.get_packed_sint32();
|
||||
int32_t sum = 0;
|
||||
for (auto val : pi) {
|
||||
sum += val;
|
||||
}
|
||||
REQUIRE(sum == 5);
|
||||
REQUIRE(std::accumulate(pi.cbegin(), pi.cend(), 0) == 5);
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::optional_string_s: {
|
||||
@@ -416,7 +414,7 @@ TEST_CASE("write complex data using pbf_writer: all") {
|
||||
pw.add_uint32(4, 66);
|
||||
pw.add_uint32(4, 66);
|
||||
|
||||
const int32_t d[] = { -17, 22 };
|
||||
const std::array<int32_t, 2> d = {{ -17, 22 }};
|
||||
pw.add_packed_sint32(7, std::begin(d), std::end(d));
|
||||
|
||||
pw.add_int64(3, 555555555);
|
||||
@@ -453,15 +451,7 @@ TEST_CASE("write complex data using pbf_writer: all") {
|
||||
}
|
||||
case 7: {
|
||||
const auto pi = item.get_packed_sint32();
|
||||
int32_t sum = 0;
|
||||
for (auto val : pi) {
|
||||
sum += val;
|
||||
}
|
||||
REQUIRE(sum == 5);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
REQUIRE(item.get_string() == "optionalstring");
|
||||
REQUIRE(std::accumulate(pi.cbegin(), pi.cend(), 0) == 5);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -577,7 +567,7 @@ TEST_CASE("write complex data using pbf_builder: all") {
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 66);
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 66);
|
||||
|
||||
const int32_t d[] = { -17, 22 };
|
||||
const std::array<int32_t, 2> d = {{ -17, 22 }};
|
||||
pw.add_packed_sint32(TestComplex::Test::packed_sint32_d, std::begin(d), std::end(d));
|
||||
|
||||
pw.add_int64(TestComplex::Test::optional_int64_j, 555555555);
|
||||
@@ -614,15 +604,7 @@ TEST_CASE("write complex data using pbf_builder: all") {
|
||||
}
|
||||
case 7: {
|
||||
const auto pi = item.get_packed_sint32();
|
||||
int32_t sum = 0;
|
||||
for (auto val : pi) {
|
||||
sum += val;
|
||||
}
|
||||
REQUIRE(sum == 5);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
REQUIRE(item.get_string() == "optionalstring");
|
||||
REQUIRE(std::accumulate(pi.cbegin(), pi.cend(), 0) == 5);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -684,3 +666,77 @@ TEST_CASE("write complex with subwriter using pbf_builder") {
|
||||
check_message(buffer_test);
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using basic_pbf_writer<fixed_size_buffer_adaptor>: all") {
|
||||
std::string data;
|
||||
data.resize(10240);
|
||||
protozero::fixed_size_buffer_adaptor buffer{&*data.begin(), data.size()};
|
||||
protozero::basic_pbf_writer<protozero::fixed_size_buffer_adaptor> pw{buffer};
|
||||
pw.add_fixed32(1, 12345678);
|
||||
|
||||
std::string sdata;
|
||||
sdata.resize(10240);
|
||||
protozero::fixed_size_buffer_adaptor submessage{&*sdata.begin(), sdata.size()};
|
||||
protozero::basic_pbf_writer<protozero::fixed_size_buffer_adaptor> pws{submessage};
|
||||
pws.add_string(1, "foobar");
|
||||
pw.add_message(5, submessage.data(), submessage.size());
|
||||
|
||||
pw.add_uint32(4, 22);
|
||||
pw.add_uint32(4, 44);
|
||||
pw.add_int64(2, -9876543);
|
||||
pw.add_uint32(4, 44);
|
||||
pw.add_uint32(4, 66);
|
||||
pw.add_uint32(4, 66);
|
||||
|
||||
const std::array<int32_t, 2> d = {{ -17, 22 }};
|
||||
pw.add_packed_sint32(7, std::begin(d), std::end(d));
|
||||
|
||||
pw.add_int64(3, 555555555);
|
||||
|
||||
protozero::pbf_reader item{buffer.data(), buffer.size()};
|
||||
|
||||
int number_of_u = 0;
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case 1: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
REQUIRE(true);
|
||||
item.skip();
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
REQUIRE(item.get_int64() == 555555555LL);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
item.skip();
|
||||
++number_of_u;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
const auto pi = item.get_packed_sint32();
|
||||
REQUIRE(std::accumulate(pi.cbegin(), pi.cend(), 0) == 5);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
REQUIRE(item.get_string() == "optionalstring");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(number_of_u == 5);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestComplex::Test msg;
|
||||
|
||||
msg.set_f(12345678);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ TEST_CASE("read double field") {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_double(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_double(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestDouble::Test msg;
|
||||
|
||||
msg.set_x(0.0);
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/double/double_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write double field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write double field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestDouble::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_double(1, 0.0);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.x() == Approx(0.0));
|
||||
}
|
||||
@@ -21,7 +22,7 @@ TEST_CASE("write double field and check with libprotobuf") {
|
||||
SECTION("positive") {
|
||||
pw.add_double(1, 4.893);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.x() == Approx(4.893));
|
||||
}
|
||||
@@ -29,7 +30,7 @@ TEST_CASE("write double field and check with libprotobuf") {
|
||||
SECTION("negative") {
|
||||
pw.add_double(1, -9232.33);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.x() == Approx(-9232.33));
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestEnum::Test msg;
|
||||
|
||||
msg.set_color(TestEnum::BLACK);
|
||||
|
||||
+10
-9
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/enum/enum_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write enum field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write enum field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestEnum::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_enum(1, 0L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::BLACK);
|
||||
}
|
||||
@@ -21,7 +22,7 @@ TEST_CASE("write enum field and check with libprotobuf") {
|
||||
SECTION("positive") {
|
||||
pw.add_enum(1, 3L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::BLUE);
|
||||
}
|
||||
@@ -29,7 +30,7 @@ TEST_CASE("write enum field and check with libprotobuf") {
|
||||
SECTION("negative") {
|
||||
pw.add_enum(1, -1L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::NEG);
|
||||
}
|
||||
@@ -37,7 +38,7 @@ TEST_CASE("write enum field and check with libprotobuf") {
|
||||
SECTION("max") {
|
||||
pw.add_enum(1, std::numeric_limits<int32_t>::max() - 1);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::MAX);
|
||||
}
|
||||
@@ -45,7 +46,7 @@ TEST_CASE("write enum field and check with libprotobuf") {
|
||||
SECTION("min") {
|
||||
pw.add_enum(1, std::numeric_limits<int32_t>::min() + 1);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::MIN);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestFixed32::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/fixed32/fixed32_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write fixed32 field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write fixed32 field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestFixed32::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_fixed32(1, 0);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 0);
|
||||
}
|
||||
@@ -21,7 +22,7 @@ TEST_CASE("write fixed32 field and check with libprotobuf") {
|
||||
SECTION("max") {
|
||||
pw.add_fixed32(1, std::numeric_limits<uint32_t>::max());
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<uint32_t>::max());
|
||||
}
|
||||
@@ -29,7 +30,7 @@ TEST_CASE("write fixed32 field and check with libprotobuf") {
|
||||
SECTION("min") {
|
||||
pw.add_fixed32(1, std::numeric_limits<uint32_t>::min());
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<uint32_t>::min());
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestFixed64::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST_CASE("read float field") {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_float(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_float(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,17 +57,17 @@ TEST_CASE("write float field") {
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_float(1, 0.0f);
|
||||
pw.add_float(1, 0.0F);
|
||||
REQUIRE(buffer == load_data("float/data-zero"));
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_float(1, 5.34f);
|
||||
pw.add_float(1, 5.34F);
|
||||
REQUIRE(buffer == load_data("float/data-pos"));
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_float(1, -1.71f);
|
||||
pw.add_float(1, -1.71F);
|
||||
REQUIRE(buffer == load_data("float/data-neg"));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestFloat::Test msg;
|
||||
|
||||
msg.set_x(0.0);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestInt32::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
|
||||
+10
-9
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/int32/int32_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write int32 field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write int32 field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestInt32::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_int32(1, 0L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 0L);
|
||||
}
|
||||
@@ -21,7 +22,7 @@ TEST_CASE("write int32 field and check with libprotobuf") {
|
||||
SECTION("positive") {
|
||||
pw.add_int32(1, 1L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 1L);
|
||||
}
|
||||
@@ -29,7 +30,7 @@ TEST_CASE("write int32 field and check with libprotobuf") {
|
||||
SECTION("negative") {
|
||||
pw.add_int32(1, -1L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == -1L);
|
||||
}
|
||||
@@ -37,7 +38,7 @@ TEST_CASE("write int32 field and check with libprotobuf") {
|
||||
SECTION("max") {
|
||||
pw.add_int32(1, std::numeric_limits<int32_t>::max());
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<int32_t>::max());
|
||||
}
|
||||
@@ -45,7 +46,7 @@ TEST_CASE("write int32 field and check with libprotobuf") {
|
||||
SECTION("min") {
|
||||
pw.add_int32(1, std::numeric_limits<int32_t>::min());
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<int32_t>::min());
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestInt64::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -6,10 +6,16 @@ TEST_CASE("read message field: string") {
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.data().data() == buffer.data());
|
||||
REQUIRE(item.data().size() == buffer.size());
|
||||
|
||||
REQUIRE(item.next());
|
||||
protozero::pbf_reader subitem{item.get_message()};
|
||||
REQUIRE_FALSE(item.next());
|
||||
|
||||
REQUIRE(item.data().data() == buffer.data() + buffer.size());
|
||||
REQUIRE(item.data().empty());
|
||||
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
@@ -21,7 +27,7 @@ TEST_CASE("read message field: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_string(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_string(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestMessage::Test msg;
|
||||
|
||||
TestMessage::Sub* submsg = msg.mutable_submessage();
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/message/message_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write message field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write message field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer_test;
|
||||
protozero::pbf_writer pbf_test{buffer_test};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
SECTION("string") {
|
||||
std::string buffer_submessage;
|
||||
protozero::pbf_writer pbf_submessage{buffer_submessage};
|
||||
pbf_submessage.add_string(1, "foobar");
|
||||
|
||||
pbf_test.add_message(1, buffer_submessage);
|
||||
pw.add_message(1, buffer_submessage);
|
||||
}
|
||||
|
||||
SECTION("string with subwriter") {
|
||||
protozero::pbf_writer pbf_submessage{pbf_test, 1};
|
||||
typename TestType::writer_type pbf_submessage{pw, 1};
|
||||
pbf_submessage.add_string(1, "foobar");
|
||||
}
|
||||
|
||||
TestMessage::Test msg;
|
||||
msg.ParseFromString(buffer_test);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
REQUIRE(msg.submessage().s() == "foobar");
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestNested::Test msg;
|
||||
msg.set_i(77);
|
||||
|
||||
|
||||
+10
-9
@@ -1,12 +1,13 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/nested/nested_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write nested message fields and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write nested message fields and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer_test;
|
||||
protozero::pbf_writer pbf_test{buffer_test};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
SECTION("string") {
|
||||
std::string buffer_subsub;
|
||||
@@ -19,23 +20,23 @@ TEST_CASE("write nested message fields and check with libprotobuf") {
|
||||
pbf_sub.add_string(1, buffer_subsub);
|
||||
pbf_sub.add_int32(2, 88);
|
||||
|
||||
pbf_test.add_message(1, buffer_sub);
|
||||
pw.add_message(1, buffer_sub);
|
||||
}
|
||||
|
||||
SECTION("with subwriter") {
|
||||
protozero::pbf_writer pbf_sub{pbf_test, 1};
|
||||
typename TestType::writer_type pbf_sub{pw, 1};
|
||||
{
|
||||
protozero::pbf_writer pbf_subsub(pbf_sub, 1);
|
||||
typename TestType::writer_type pbf_subsub(pbf_sub, 1);
|
||||
pbf_subsub.add_string(1, "foobar");
|
||||
pbf_subsub.add_int32(2, 99);
|
||||
}
|
||||
pbf_sub.add_int32(2, 88);
|
||||
}
|
||||
|
||||
pbf_test.add_int32(2, 77);
|
||||
pw.add_int32(2, 77);
|
||||
|
||||
TestNested::Test msg;
|
||||
msg.ParseFromString(buffer_test);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 77);
|
||||
REQUIRE(msg.sub().i() == 88);
|
||||
|
||||
@@ -48,7 +48,7 @@ TEST_CASE("read repeated fields: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_int32(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_int32(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeated::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/repeated/repeated_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write repeated fields and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write repeated fields and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestRepeated::Test msg;
|
||||
|
||||
SECTION("one") {
|
||||
pw.add_int32(1, 0L);
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i().size() == 1);
|
||||
REQUIRE(msg.i(0) == 0L);
|
||||
@@ -26,7 +27,7 @@ TEST_CASE("write repeated fields and check with libprotobuf") {
|
||||
pw.add_int32(1, std::numeric_limits<int32_t>::max());
|
||||
pw.add_int32(1, std::numeric_limits<int32_t>::min());
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i().size() == 5);
|
||||
REQUIRE(msg.i(0) == 0L);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
TEST_CASE("read repeated packed bool field: empty") {
|
||||
const std::string buffer = load_data("repeated_packed_bool/data-empty");
|
||||
|
||||
@@ -51,7 +53,7 @@ TEST_CASE("read repeated packed bool field: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_packed_bool(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_packed_bool(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,21 +62,21 @@ TEST_CASE("write repeated packed bool field") {
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
const bool data[] = { true };
|
||||
const std::array<bool, 1> data = {{ true }};
|
||||
pw.add_packed_bool(1, std::begin(data), std::begin(data) /* !!!! */);
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_bool/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
const bool data[] = { true };
|
||||
const std::array<bool, 1> data = {{ true }};
|
||||
pw.add_packed_bool(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_bool/data-one"));
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
const bool data[] = { true, true, false, true };
|
||||
const std::array<bool, 4> data = {{ true, true, false, true }};
|
||||
pw.add_packed_bool(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_bool/data-many"));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedBool::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
TEST_CASE("read repeated packed double field") {
|
||||
// Run these tests twice, the second time we basically move the data
|
||||
// one byte down in the buffer. It doesn't matter how the data or buffer
|
||||
@@ -82,7 +84,7 @@ TEST_CASE("read repeated packed double field") {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_packed_double(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_packed_double(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,21 +95,23 @@ TEST_CASE("write repeated packed double field") {
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
const double data[] = { 17.34 };
|
||||
const std::array<double, 1> data = {{ 17.34 }};
|
||||
pw.add_packed_double(1, std::begin(data), std::begin(data) /* !!!! */);
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_double/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
const double data[] = { 17.34 };
|
||||
const std::array<double, 1> data = {{ 17.34 }};
|
||||
pw.add_packed_double(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_double/data-one"));
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
const double data[] = { 17.34, 0.0, 1.0, std::numeric_limits<double>::min(), std::numeric_limits<double>::max() };
|
||||
const std::array<double, 5> data = {{ 17.34, 0.0, 1.0,
|
||||
std::numeric_limits<double>::min(),
|
||||
std::numeric_limits<double>::max() }};
|
||||
pw.add_packed_double(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_double/data-many"));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedDouble::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
TEST_CASE("read repeated packed enum field: empty") {
|
||||
const std::string buffer = load_data("repeated_packed_enum/data-empty");
|
||||
|
||||
@@ -46,7 +48,7 @@ TEST_CASE("read repeated packed enum field: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_packed_enum(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_packed_enum(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,21 +57,21 @@ TEST_CASE("write repeated packed enum field") {
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
const int32_t data[] = { 0 /* BLACK */ };
|
||||
const std::array<int32_t, 1> data = {{ 0 /* BLACK */ }};
|
||||
pw.add_packed_enum(1, std::begin(data), std::begin(data) /* !!!! */);
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_enum/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
const int32_t data[] = { 0 /* BLACK */ };
|
||||
const std::array<int32_t, 1> data = {{ 0 /* BLACK */ }};
|
||||
pw.add_packed_enum(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_enum/data-one"));
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
const int32_t data[] = { 0 /* BLACK */, 3 /* BLUE */, 2 /* GREEN */ };
|
||||
const std::array<int32_t, 3> data = {{ 0 /* BLACK */, 3 /* BLUE */, 2 /* GREEN */ }};
|
||||
pw.add_packed_enum(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_enum/data-many"));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedEnum::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedFixed32::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
+21
-16
@@ -1,35 +1,39 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
|
||||
#include "t/repeated_packed_fixed32/repeated_packed_fixed32_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write repeated packed fixed32 field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write repeated packed fixed32 field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestRepeatedPackedFixed32::Test msg;
|
||||
|
||||
SECTION("empty") {
|
||||
uint32_t data[] = { 17UL };
|
||||
const std::array<uint32_t, 1> data = {{ 17UL }};
|
||||
pw.add_packed_fixed32(1, std::begin(data), std::begin(data) /* !!!! */);
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
uint32_t data[] = { 17UL };
|
||||
const std::array<uint32_t, 1> data = {{ 17UL }};
|
||||
pw.add_packed_fixed32(1, std::begin(data), std::end(data));
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i().size() == 1);
|
||||
REQUIRE(msg.i(0) == 17UL);
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
uint32_t data[] = { 17UL, 0UL, 1UL, std::numeric_limits<uint32_t>::max() };
|
||||
const std::array<uint32_t, 4> data = {{ 17UL, 0UL, 1UL, std::numeric_limits<uint32_t>::max() }};
|
||||
pw.add_packed_fixed32(1, std::begin(data), std::end(data));
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i().size() == 4);
|
||||
REQUIRE(msg.i(0) == 17UL);
|
||||
@@ -39,17 +43,18 @@ TEST_CASE("write repeated packed fixed32 field and check with libprotobuf") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write from different types of iterators and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write from different types of iterators and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestRepeatedPackedFixed32::Test msg;
|
||||
|
||||
SECTION("from uint16_t") {
|
||||
uint16_t data[] = { 1, 4, 9, 16, 25 };
|
||||
const std::array<uint16_t, 5> data = {{ 1, 4, 9, 16, 25 }};
|
||||
|
||||
pw.add_packed_fixed32(1, std::begin(data), std::end(data));
|
||||
pw.template add_packed_fixed<uint32_t>(1, std::begin(data), std::end(data));
|
||||
}
|
||||
|
||||
SECTION("from string") {
|
||||
@@ -59,10 +64,10 @@ TEST_CASE("write from different types of iterators and check with libprotobuf")
|
||||
std::istream_iterator<uint32_t> eod;
|
||||
std::istream_iterator<uint32_t> it(sdata);
|
||||
|
||||
pw.add_packed_fixed32(1, it, eod);
|
||||
pw.template add_packed_fixed<uint32_t>(1, it, eod);
|
||||
}
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i().size() == 5);
|
||||
REQUIRE(msg.i(0) == 1);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedFixed64::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
TEST_CASE("read repeated packed float field") {
|
||||
// Run these tests twice, the second time we basically move the data
|
||||
// one byte down in the buffer. It doesn't matter how the data or buffer
|
||||
@@ -28,7 +30,7 @@ TEST_CASE("read repeated packed float field") {
|
||||
auto it_range = item.get_packed_float();
|
||||
REQUIRE_FALSE(item.next());
|
||||
|
||||
REQUIRE(*it_range.begin() == Approx(17.34f));
|
||||
REQUIRE(*it_range.begin() == Approx(17.34F));
|
||||
REQUIRE(std::next(it_range.begin()) == it_range.end());
|
||||
}
|
||||
|
||||
@@ -41,9 +43,9 @@ TEST_CASE("read repeated packed float field") {
|
||||
REQUIRE_FALSE(item.next());
|
||||
|
||||
auto it = it_range.begin();
|
||||
REQUIRE(*it++ == Approx(17.34f));
|
||||
REQUIRE(*it++ == Approx( 0.0f));
|
||||
REQUIRE(*it++ == Approx( 1.0f));
|
||||
REQUIRE(*it++ == Approx(17.34F));
|
||||
REQUIRE(*it++ == Approx( 0.0F));
|
||||
REQUIRE(*it++ == Approx( 1.0F));
|
||||
REQUIRE(*it++ == std::numeric_limits<float>::min());
|
||||
REQUIRE(*it++ == std::numeric_limits<float>::max());
|
||||
REQUIRE(it == it_range.end());
|
||||
@@ -55,7 +57,7 @@ TEST_CASE("read repeated packed float field") {
|
||||
for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
|
||||
protozero::pbf_reader item{abuffer.data() + n, i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_packed_float(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_packed_float(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,21 +68,21 @@ TEST_CASE("write repeated packed float field") {
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
float data[] = { 17.34f };
|
||||
const std::array<float, 1> data = {{ 17.34F }};
|
||||
pw.add_packed_float(1, std::begin(data), std::begin(data) /* !!!! */);
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_float/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
float data[] = { 17.34f };
|
||||
const std::array<float, 1> data = {{ 17.34F }};
|
||||
pw.add_packed_float(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_float/data-one"));
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
float data[] = { 17.34f, 0.0f, 1.0f, std::numeric_limits<float>::min(), std::numeric_limits<float>::max() };
|
||||
const std::array<float, 5> data = {{ 17.34F, 0.0F, 1.0F, std::numeric_limits<float>::min(), std::numeric_limits<float>::max() }};
|
||||
pw.add_packed_float(1, std::begin(data), std::end(data));
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_float/data-many"));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedFloat::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedInt32::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedInt64::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
+1
-1
@@ -25,6 +25,6 @@ TEST_CASE("length value must be dividable by sizeof(T)") {
|
||||
protozero::pbf_reader item{data};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_packed_sfixed32(), const protozero::invalid_length_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_packed_sfixed32(), protozero::invalid_length_exception);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedSFixed32::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedSFixed64::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedSInt32::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedSInt64::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedUInt32::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestRepeatedPackedUInt64::Test msg;
|
||||
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
@@ -131,7 +131,7 @@ TEST_CASE("rollback when using packed_field functions") {
|
||||
protozero::packed_field_sint64 field{pw, 1};
|
||||
field.add_element(1L);
|
||||
field.rollback();
|
||||
REQUIRE_THROWS_AS(field.add_element(1L), const assert_error&);
|
||||
REQUIRE_THROWS_AS(field.add_element(1L), assert_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ TEST_CASE("rollback when using submessages") {
|
||||
TEST_CASE("rollback on parent message is never allowed") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
REQUIRE_THROWS_AS(pw.rollback(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(pw.rollback(), assert_error);
|
||||
}
|
||||
|
||||
TEST_CASE("rollback on parent message is not allowed even if there is a submessage") {
|
||||
@@ -183,7 +183,7 @@ TEST_CASE("rollback on parent message is not allowed even if there is a submessa
|
||||
{
|
||||
protozero::pbf_writer pws{pw, 1};
|
||||
pws.add_string(1, "foobar");
|
||||
REQUIRE_THROWS_AS(pw.rollback(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(pw.rollback(), assert_error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ TEST_CASE("rollback on message is not allowed if there is a nested submessage")
|
||||
protozero::pbf_writer pws{pw, 1};
|
||||
pws.add_string(1, "foobar");
|
||||
protozero::pbf_writer pws2{pws, 1};
|
||||
REQUIRE_THROWS_AS(pws.rollback(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(pws.rollback(), assert_error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestSFixed32::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestSFixed64::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestSInt32::Test msg;
|
||||
|
||||
msg.set_i(0L);
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestSInt64::Test msg;
|
||||
|
||||
msg.set_i(0LL);
|
||||
|
||||
+2
-2
@@ -116,7 +116,7 @@ TEST_CASE("exceptional cases") {
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE_THROWS_AS(item.next(), const protozero::unknown_pbf_wire_type_exception&);
|
||||
REQUIRE_THROWS_AS(item.next(), protozero::unknown_pbf_wire_type_exception);
|
||||
}
|
||||
|
||||
SECTION("check that skip() throws on short buffer") {
|
||||
@@ -124,7 +124,7 @@ TEST_CASE("exceptional cases") {
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.skip(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.skip(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ TEST_CASE("read string field using get_string: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_string(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_string(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ TEST_CASE("read string field using get_view: end of buffer") {
|
||||
for (std::string::size_type i = 1; i < buffer.size(); ++i) {
|
||||
protozero::pbf_reader item{buffer.data(), i};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_view(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_view(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestString::Test msg;
|
||||
|
||||
msg.set_s("");
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
|
||||
#include <test.hpp>
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/string/string_testcase.pb.h"
|
||||
|
||||
TEST_CASE("write string field and check with libprotobuf") {
|
||||
TEMPLATE_TEST_CASE("write string field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestString::Test msg;
|
||||
|
||||
SECTION("empty") {
|
||||
pw.add_string(1, "");
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s().empty());
|
||||
}
|
||||
@@ -21,7 +22,7 @@ TEST_CASE("write string field and check with libprotobuf") {
|
||||
SECTION("one") {
|
||||
pw.add_string(1, "x");
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s() == "x");
|
||||
}
|
||||
@@ -29,7 +30,7 @@ TEST_CASE("write string field and check with libprotobuf") {
|
||||
SECTION("string") {
|
||||
pw.add_string(1, "foobar");
|
||||
|
||||
msg.ParseFromString(buffer);
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s() == "foobar");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -17,9 +19,7 @@ inline std::vector<uint32_t> read_data(const std::string& data) {
|
||||
switch (message.tag_and_type()) {
|
||||
case tag_and_type(ExampleMsg::repeated_uint32_x, protozero::pbf_wire_type::length_delimited): {
|
||||
const auto xit = message.get_packed_uint32();
|
||||
for (const auto value : xit) {
|
||||
values.push_back(value);
|
||||
}
|
||||
std::copy(xit.cbegin(), xit.cend(), std::back_inserter(values));
|
||||
}
|
||||
break;
|
||||
case tag_and_type(ExampleMsg::repeated_uint32_x, protozero::pbf_wire_type::varint): {
|
||||
@@ -28,7 +28,7 @@ inline std::vector<uint32_t> read_data(const std::string& data) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
message.skip();
|
||||
REQUIRE(false); // should never be here
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,7 @@ inline std::vector<uint32_t> read_data_packed(const std::string& data) {
|
||||
protozero::pbf_message<ExampleMsg> message{data};
|
||||
while (message.next(ExampleMsg::repeated_uint32_x, protozero::pbf_wire_type::length_delimited)) {
|
||||
const auto xit = message.get_packed_uint32();
|
||||
for (const auto value : xit) {
|
||||
values.push_back(value);
|
||||
}
|
||||
std::copy(xit.cbegin(), xit.cend(), std::back_inserter(values));
|
||||
}
|
||||
|
||||
return values;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
|
||||
std::string out;
|
||||
|
||||
|
||||
+5
-5
@@ -11,19 +11,19 @@ inline void check_tag(const std::string& buffer, protozero::pbf_tag_type tag) {
|
||||
}
|
||||
|
||||
TEST_CASE("read tag: 1") {
|
||||
check_tag(load_data("tags/data-tag-1"), 1ul);
|
||||
check_tag(load_data("tags/data-tag-1"), 1UL);
|
||||
}
|
||||
|
||||
TEST_CASE("read tag: 200") {
|
||||
check_tag(load_data("tags/data-tag-200"), 200ul);
|
||||
check_tag(load_data("tags/data-tag-200"), 200UL);
|
||||
}
|
||||
|
||||
TEST_CASE("read tag: 200000") {
|
||||
check_tag(load_data("tags/data-tag-200000"), 200000ul);
|
||||
check_tag(load_data("tags/data-tag-200000"), 200000UL);
|
||||
}
|
||||
|
||||
TEST_CASE("read tag: max") {
|
||||
check_tag(load_data("tags/data-tag-max"), (1ul << 29u) - 1u);
|
||||
check_tag(load_data("tags/data-tag-max"), (1UL << 29U) - 1U);
|
||||
}
|
||||
|
||||
TEST_CASE("write tags") {
|
||||
@@ -46,7 +46,7 @@ TEST_CASE("write tags") {
|
||||
}
|
||||
|
||||
SECTION("tag max") {
|
||||
pw.add_int32(static_cast<int32_t>((1ul << 29u) - 1u), 333L);
|
||||
pw.add_int32(static_cast<int32_t>((1UL << 29U) - 1U), 333L);
|
||||
REQUIRE(buffer == load_data("tags/data-tag-max"));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
|
||||
{
|
||||
TestTags::Test1 msg;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestUInt32::Test msg;
|
||||
|
||||
msg.set_i(0ul);
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main(int c, char *argv[]) {
|
||||
int main() {
|
||||
TestUInt64::Test msg;
|
||||
|
||||
msg.set_i(0ul);
|
||||
|
||||
@@ -11,6 +11,7 @@ static 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 "";
|
||||
}
|
||||
|
||||
@@ -42,6 +43,7 @@ TEST_CASE("reading vector tiles") {
|
||||
}
|
||||
} else {
|
||||
item.skip();
|
||||
REQUIRE(false); // should never be here
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ TEST_CASE("check assert on non-varint access to varint") {
|
||||
REQUIRE(item.next());
|
||||
|
||||
REQUIRE(item.get_int32() == 0);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_string(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), assert_error);
|
||||
REQUIRE_THROWS_AS(item.get_string(), assert_error);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), assert_error);
|
||||
}
|
||||
|
||||
// protobuf wire type 1
|
||||
@@ -21,10 +21,10 @@ TEST_CASE("check assert on non-fixed access to fixed64") {
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
REQUIRE_THROWS_AS(item.get_int32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_int32(), assert_error);
|
||||
REQUIRE(item.get_fixed64() == 0);
|
||||
REQUIRE_THROWS_AS(item.get_string(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_string(), assert_error);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), assert_error);
|
||||
}
|
||||
|
||||
// protobuf wire type 2
|
||||
@@ -34,10 +34,10 @@ TEST_CASE("check assert on non-string access to string") {
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
REQUIRE_THROWS_AS(item.get_int32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_int32(), assert_error);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), assert_error);
|
||||
REQUIRE(item.get_string() == "foobar");
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), assert_error);
|
||||
}
|
||||
|
||||
// protobuf wire type 5
|
||||
@@ -47,9 +47,9 @@ TEST_CASE("check assert on non-fixed access to fixed32") {
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
REQUIRE_THROWS_AS(item.get_int32(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_string(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(item.get_int32(), assert_error);
|
||||
REQUIRE_THROWS_AS(item.get_fixed64(), assert_error);
|
||||
REQUIRE_THROWS_AS(item.get_string(), assert_error);
|
||||
REQUIRE(item.get_fixed32() == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
|
||||
set(UNIT_TESTS data_view
|
||||
basic
|
||||
buffer
|
||||
endian
|
||||
exceptions
|
||||
iterators
|
||||
varint
|
||||
zigzag)
|
||||
|
||||
|
||||
+84
-44
@@ -1,6 +1,36 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template <typename T>
|
||||
struct movable_not_copyable {
|
||||
constexpr static bool value = !std::is_copy_constructible<T>::value &&
|
||||
!std::is_copy_assignable<T>::value &&
|
||||
std::is_nothrow_move_constructible<T>::value &&
|
||||
std::is_nothrow_move_assignable<T>::value;
|
||||
};
|
||||
|
||||
static_assert(movable_not_copyable<protozero::pbf_writer>::value, "pbf_writer should be nothrow movable, but not copyable");
|
||||
|
||||
enum class dummy : protozero::pbf_tag_type {};
|
||||
static_assert(movable_not_copyable<protozero::pbf_builder<dummy>>::value, "pbf_builder should be nothrow movable, but not copyable");
|
||||
|
||||
static_assert(movable_not_copyable<protozero::packed_field_bool>::value, "packed_field_bool should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_enum>::value, "packed_field_enum should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_int32>::value, "packed_field_int32 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_sint32>::value, "packed_field_sint32 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_uint32>::value, "packed_field_uint32 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_int64>::value, "packed_field_int64 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_sint64>::value, "packed_field_sint64 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_uint64>::value, "packed_field_uint64 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_fixed32>::value, "packed_field_fixed32 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_sfixed32>::value, "packed_field_sfixed32 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_fixed64>::value, "packed_field_fixed64 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_sfixed64>::value, "packed_field_sfixed64 should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_float>::value, "packed_field_float should be nothrow movable, but not copyable");
|
||||
static_assert(movable_not_copyable<protozero::packed_field_double>::value, "packed_field_double should be nothrow movable, but not copyable");
|
||||
|
||||
TEST_CASE("default constructed pbf_reader is okay") {
|
||||
protozero::pbf_reader item;
|
||||
|
||||
@@ -19,10 +49,10 @@ TEST_CASE("empty buffer in pbf_reader is okay") {
|
||||
}
|
||||
|
||||
TEST_CASE("check every possible value for single byte in buffer") {
|
||||
char buffer;
|
||||
char buffer[1];
|
||||
for (int i = 0; i <= 255; ++i) {
|
||||
buffer = static_cast<char>(i);
|
||||
protozero::pbf_reader item{&buffer, 1};
|
||||
buffer[0] = static_cast<char>(i);
|
||||
protozero::pbf_reader item{buffer, 1};
|
||||
|
||||
REQUIRE(item.length() == 1);
|
||||
REQUIRE_FALSE(!item); // test operator bool()
|
||||
@@ -31,54 +61,64 @@ TEST_CASE("check every possible value for single byte in buffer") {
|
||||
}
|
||||
|
||||
TEST_CASE("next() should throw when illegal wire type is encountered") {
|
||||
const char buffer = 1u << 3u | 7u;
|
||||
const char buffer[1] = {1U << 3U | 7U};
|
||||
|
||||
protozero::pbf_reader item{&buffer, 1};
|
||||
REQUIRE_THROWS_AS(item.next(), const protozero::unknown_pbf_wire_type_exception&);
|
||||
protozero::pbf_reader item{buffer, 1};
|
||||
REQUIRE_THROWS_AS(item.next(), protozero::unknown_pbf_wire_type_exception);
|
||||
}
|
||||
|
||||
TEST_CASE("next() should throw when illegal tag is encountered") {
|
||||
TEST_CASE("next() should throw when illegal tag 0 is encountered") {
|
||||
std::string data;
|
||||
|
||||
SECTION("tag 0") {
|
||||
protozero::write_varint(std::back_inserter(data), 0u << 3u | 1u);
|
||||
}
|
||||
|
||||
SECTION("tag 19000") {
|
||||
protozero::write_varint(std::back_inserter(data), 19000u << 3u | 1u);
|
||||
}
|
||||
|
||||
SECTION("tag 19001") {
|
||||
protozero::write_varint(std::back_inserter(data), 19001u << 3u | 1u);
|
||||
}
|
||||
|
||||
SECTION("tag 19999") {
|
||||
protozero::write_varint(std::back_inserter(data), 19999u << 3u | 1u);
|
||||
}
|
||||
|
||||
protozero::add_varint_to_buffer(&data, 0U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE_THROWS_AS(item.next(), const protozero::invalid_tag_exception&);
|
||||
REQUIRE_THROWS_AS(item.next(), protozero::invalid_tag_exception);
|
||||
}
|
||||
|
||||
TEST_CASE("next() works when a legal tag is encountered") {
|
||||
TEST_CASE("next() should throw when illegal tag 19000 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, 19000U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE_THROWS_AS(item.next(), protozero::invalid_tag_exception);
|
||||
}
|
||||
|
||||
SECTION("tag 1") {
|
||||
protozero::write_varint(std::back_inserter(data), 1u << 3u | 1u);
|
||||
}
|
||||
TEST_CASE("next() should throw when illegal tag 19001 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, 19001U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE_THROWS_AS(item.next(), protozero::invalid_tag_exception);
|
||||
}
|
||||
|
||||
SECTION("tag 18999") {
|
||||
protozero::write_varint(std::back_inserter(data), 18999u << 3u | 1u);
|
||||
}
|
||||
TEST_CASE("next() should throw when illegal tag 19999 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, 19999U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE_THROWS_AS(item.next(), protozero::invalid_tag_exception);
|
||||
}
|
||||
|
||||
SECTION("tag 20000") {
|
||||
protozero::write_varint(std::back_inserter(data), 20000u << 3u | 1u);
|
||||
}
|
||||
TEST_CASE("next() works when legal tag 1 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, 1U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE(item.next());
|
||||
}
|
||||
|
||||
SECTION("tag 1^29 - 1") {
|
||||
protozero::write_varint(std::back_inserter(data), ((1u << 29u) - 1u) << 3u | 1u);
|
||||
}
|
||||
TEST_CASE("next() works when legal tag 18999 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, 18999U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("next() works when legal tag 20000 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, 20000U << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("next() works when legal tag 1^29 - 1 is encountered") {
|
||||
std::string data;
|
||||
protozero::add_varint_to_buffer(&data, ((1UL << 29U) - 1U) << 3U | 1U);
|
||||
protozero::pbf_reader item{data};
|
||||
REQUIRE(item.next());
|
||||
}
|
||||
@@ -87,15 +127,15 @@ TEST_CASE("pbf_writer asserts on invalid tags") {
|
||||
std::string data;
|
||||
protozero::pbf_writer writer{data};
|
||||
|
||||
REQUIRE_THROWS_AS(writer.add_int32(0, 123), const assert_error&);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(0, 123), assert_error);
|
||||
writer.add_int32(1, 123);
|
||||
writer.add_int32(2, 123);
|
||||
writer.add_int32(18999, 123);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(19000, 123), const assert_error&);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(19001, 123), const assert_error&);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(19999, 123), const assert_error&);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(19000, 123), assert_error);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(19001, 123), assert_error);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(19999, 123), assert_error);
|
||||
writer.add_int32(20000, 123);
|
||||
writer.add_int32((1u << 29u) - 1u, 123);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(1u << 29u, 123), const assert_error&);
|
||||
writer.add_int32((1U << 29U) - 1U, 123);
|
||||
REQUIRE_THROWS_AS(writer.add_int32(1U << 29U, 123), assert_error);
|
||||
}
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
TEMPLATE_TEST_CASE("Use various buffer types", "", buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
TestType tt;
|
||||
auto* buffer = &tt.buffer();
|
||||
|
||||
using bc = protozero::buffer_customization<typename TestType::type>;
|
||||
|
||||
REQUIRE(bc::size(buffer) == 0);
|
||||
|
||||
bc::append(buffer, "abc def ghi", 11);
|
||||
REQUIRE(bc::size(buffer) == 11);
|
||||
|
||||
bc::append_zeros(buffer, 3);
|
||||
REQUIRE(bc::size(buffer) == 14);
|
||||
|
||||
bc::resize(buffer, 11);
|
||||
REQUIRE(bc::size(buffer) == 11);
|
||||
|
||||
bc::append(buffer, " jkl", 4);
|
||||
REQUIRE(bc::size(buffer) == 15);
|
||||
|
||||
bc::erase_range(buffer, 4, 8);
|
||||
REQUIRE(bc::size(buffer) == 11);
|
||||
REQUIRE(std::equal(bc::at_pos(buffer, 0),
|
||||
bc::at_pos(buffer, bc::size(buffer)),
|
||||
"abc ghi jkl"));
|
||||
|
||||
buffer->push_back(' ');
|
||||
buffer->push_back('x');
|
||||
buffer->push_back('y');
|
||||
REQUIRE(bc::size(buffer) == 14);
|
||||
REQUIRE(std::equal(bc::at_pos(buffer, 0),
|
||||
bc::at_pos(buffer, bc::size(buffer)),
|
||||
"abc ghi jkl xy"));
|
||||
|
||||
REQUIRE(std::equal(buffer->cbegin(), buffer->cend(), "abc ghi jkl xy"));
|
||||
}
|
||||
|
||||
TEST_CASE("fixed_size_buffer_adaptor has limited size") {
|
||||
std::array<char, 5> data = {{0}};
|
||||
protozero::fixed_size_buffer_adaptor fsba{&*data.begin(), data.size()};
|
||||
REQUIRE_THROWS_AS(protozero::buffer_customization<protozero::fixed_size_buffer_adaptor>::append(&fsba, "0123456789", 10), std::length_error);
|
||||
}
|
||||
+1
-1
@@ -61,7 +61,7 @@ TEST_CASE("convert data_view to std::string") {
|
||||
// that one contains the protozero_assert() which generates the exception.
|
||||
TEST_CASE("converting default constructed data_view to string fails") {
|
||||
const protozero::data_view view{};
|
||||
REQUIRE_THROWS_AS(view.to_string(), const assert_error&);
|
||||
REQUIRE_THROWS_AS(view.to_string(), assert_error);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+18
-18
@@ -7,14 +7,14 @@
|
||||
#include <protozero/byteswap.hpp>
|
||||
|
||||
static int32_t check_swap_4(int32_t data) noexcept {
|
||||
protozero::detail::byteswap_inplace(&data);
|
||||
protozero::detail::byteswap_inplace(&data);
|
||||
protozero::byteswap_inplace(&data);
|
||||
protozero::byteswap_inplace(&data);
|
||||
return data;
|
||||
}
|
||||
|
||||
static int64_t check_swap_8(int64_t data) noexcept {
|
||||
protozero::detail::byteswap_inplace(&data);
|
||||
protozero::detail::byteswap_inplace(&data);
|
||||
protozero::byteswap_inplace(&data);
|
||||
protozero::byteswap_inplace(&data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -30,43 +30,43 @@ TEST_CASE("byte swapping") {
|
||||
REQUIRE(0 == check_swap_8(0));
|
||||
REQUIRE(1 == check_swap_8(1));
|
||||
REQUIRE(-1 == check_swap_8(-1));
|
||||
REQUIRE(395503ll == check_swap_8(395503ll));
|
||||
REQUIRE(-804022ll == check_swap_8(-804022ll));
|
||||
REQUIRE(3280329805ll == check_swap_8(3280329805ll));
|
||||
REQUIRE(-2489204041ll == check_swap_8(-2489204041ll));
|
||||
REQUIRE(395503LL == check_swap_8(395503LL));
|
||||
REQUIRE(-804022LL == check_swap_8(-804022LL));
|
||||
REQUIRE(3280329805LL == check_swap_8(3280329805LL));
|
||||
REQUIRE(-2489204041LL == check_swap_8(-2489204041LL));
|
||||
REQUIRE(std::numeric_limits<int64_t>::max() == check_swap_8(std::numeric_limits<int64_t>::max()));
|
||||
REQUIRE(std::numeric_limits<int64_t>::min() == check_swap_8(std::numeric_limits<int64_t>::min()));
|
||||
}
|
||||
|
||||
TEST_CASE("byte swap uint32_t") {
|
||||
uint32_t a = 17;
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
|
||||
REQUIRE(17 == a);
|
||||
}
|
||||
|
||||
TEST_CASE("byte swap uint64_t") {
|
||||
uint64_t a = 347529808;
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
|
||||
REQUIRE(347529808 == a);
|
||||
}
|
||||
|
||||
TEST_CASE("byte swap double") {
|
||||
double a = 1.1;
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
|
||||
REQUIRE(a == Approx(1.1));
|
||||
}
|
||||
|
||||
TEST_CASE("byte swap float") {
|
||||
float a = 1.1f;
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
protozero::detail::byteswap_inplace(&a);
|
||||
float a = 1.1F;
|
||||
protozero::byteswap_inplace(&a);
|
||||
protozero::byteswap_inplace(&a);
|
||||
|
||||
REQUIRE(a == Approx(1.1f));
|
||||
REQUIRE(a == Approx(1.1F));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
TEST_CASE("default constructed varint_iterators are equal") {
|
||||
protozero::const_varint_iterator<uint32_t> a{};
|
||||
protozero::const_varint_iterator<uint32_t> b{};
|
||||
|
||||
protozero::iterator_range<protozero::const_varint_iterator<uint32_t>> r{};
|
||||
|
||||
REQUIRE(a == a);
|
||||
REQUIRE(a == b);
|
||||
REQUIRE(a == r.begin());
|
||||
REQUIRE(a == r.end());
|
||||
REQUIRE(r.empty());
|
||||
REQUIRE(r.size() == 0); // NOLINT(readability-container-size-empty)
|
||||
REQUIRE(r.begin() == r.end());
|
||||
}
|
||||
|
||||
+74
-20
@@ -26,12 +26,12 @@ TEST_CASE("varint") {
|
||||
}
|
||||
|
||||
SECTION("encode/decode uint32") {
|
||||
pw.add_uint32(1, 17u);
|
||||
pw.add_uint32(1, 17U);
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
SECTION("get") {
|
||||
REQUIRE(17u == item.get_uint32());
|
||||
REQUIRE(17U == item.get_uint32());
|
||||
}
|
||||
|
||||
SECTION("skip") {
|
||||
@@ -42,12 +42,12 @@ TEST_CASE("varint") {
|
||||
}
|
||||
|
||||
SECTION("encode/decode uint64") {
|
||||
pw.add_uint64(1, (1ull << 40u));
|
||||
pw.add_uint64(1, (1ULL << 40U));
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
SECTION("get") {
|
||||
REQUIRE((1ull << 40u) == item.get_uint64());
|
||||
REQUIRE((1ULL << 40U) == item.get_uint64());
|
||||
}
|
||||
|
||||
SECTION("skip") {
|
||||
@@ -58,47 +58,47 @@ TEST_CASE("varint") {
|
||||
}
|
||||
|
||||
SECTION("short buffer while parsing varint") {
|
||||
pw.add_uint64(1, (1ull << 40u));
|
||||
pw.add_uint64(1, (1ULL << 40U));
|
||||
buffer.resize(buffer.size() - 1); // "remove" last byte from buffer
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
SECTION("get") {
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
|
||||
SECTION("skip") {
|
||||
REQUIRE_THROWS_AS(item.skip(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.skip(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("data corruption in buffer while parsing varint)") {
|
||||
pw.add_uint64(1, (1ull << 20u));
|
||||
buffer[buffer.size() - 1] += 0x80; // pretend the varint goes on
|
||||
pw.add_uint64(1, (1ULL << 20U));
|
||||
buffer[buffer.size() - 1] += static_cast<char>(0x80); // pretend the varint goes on
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
SECTION("get") {
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
|
||||
SECTION("skip") {
|
||||
REQUIRE_THROWS_AS(item.skip(), const protozero::end_of_buffer_exception&);
|
||||
REQUIRE_THROWS_AS(item.skip(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("data corruption in buffer while parsing varint (max length varint)") {
|
||||
pw.add_uint64(1, std::numeric_limits<uint64_t>::max());
|
||||
buffer[buffer.size() - 1] += 0x80; // pretend the varint goes on
|
||||
buffer[buffer.size() - 1] += static_cast<char>(0x80); // pretend the varint goes on
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
|
||||
SECTION("get") {
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), const protozero::varint_too_long_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), protozero::varint_too_long_exception);
|
||||
}
|
||||
|
||||
SECTION("skip") {
|
||||
REQUIRE_THROWS_AS(item.skip(), const protozero::varint_too_long_exception&);
|
||||
REQUIRE_THROWS_AS(item.skip(), protozero::varint_too_long_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,15 +107,15 @@ TEST_CASE("10-byte varint") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
pw.add_uint64(1, 1);
|
||||
buffer.back() = static_cast<char>(0xffu);
|
||||
buffer.back() = static_cast<char>(0xffU);
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
buffer.push_back(static_cast<char>(0xffu));
|
||||
buffer.push_back(static_cast<char>(0xffU));
|
||||
}
|
||||
buffer.push_back(0x02);
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), const protozero::varint_too_long_exception&);
|
||||
REQUIRE_THROWS_AS(item.get_uint64(), protozero::varint_too_long_exception);
|
||||
}
|
||||
|
||||
TEST_CASE("lots of varints back and forth") {
|
||||
@@ -152,7 +152,7 @@ TEST_CASE("lots of varints back and forth") {
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 63; ++i) {
|
||||
const auto n = static_cast<int64_t>(1ull << i);
|
||||
const auto n = static_cast<int64_t>(1ULL << i);
|
||||
protozero::pbf_writer pw{buffer};
|
||||
pw.add_int64(1, n);
|
||||
protozero::pbf_reader item{buffer};
|
||||
@@ -163,7 +163,7 @@ TEST_CASE("lots of varints back and forth") {
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 63; ++i) {
|
||||
const int64_t n = - static_cast<int64_t>(1ull << i);
|
||||
const int64_t n = - static_cast<int64_t>(1ULL << i);
|
||||
protozero::pbf_writer pw{buffer};
|
||||
pw.add_int64(1, n);
|
||||
protozero::pbf_reader item{buffer};
|
||||
@@ -174,7 +174,7 @@ TEST_CASE("lots of varints back and forth") {
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 64; ++i) {
|
||||
const uint64_t n = 1ull << i;
|
||||
const uint64_t n = 1ULL << i;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
pw.add_uint64(1, n);
|
||||
protozero::pbf_reader item{buffer};
|
||||
@@ -185,3 +185,57 @@ TEST_CASE("lots of varints back and forth") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("skip_varint with empty buffer throws") {
|
||||
const char* buffer = "";
|
||||
REQUIRE_THROWS_AS(protozero::skip_varint(&buffer, buffer), protozero::end_of_buffer_exception);
|
||||
}
|
||||
|
||||
TEST_CASE("call skip_varint with every possible value for single byte in buffer") {
|
||||
char buffer[1];
|
||||
for (int i = 0; i <= 127; ++i) {
|
||||
buffer[0] = static_cast<char>(i);
|
||||
const char* b = buffer;
|
||||
protozero::skip_varint(&b, buffer + 1);
|
||||
REQUIRE(b == buffer + 1);
|
||||
}
|
||||
for (int i = 128; i <= 255; ++i) {
|
||||
buffer[0] = static_cast<char>(i);
|
||||
const char* b = buffer;
|
||||
REQUIRE_THROWS_AS(protozero::skip_varint(&b, buffer + 1), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("decode_varint with empty buffer throws") {
|
||||
const char* buffer = "";
|
||||
REQUIRE_THROWS_AS(protozero::decode_varint(&buffer, buffer), protozero::end_of_buffer_exception);
|
||||
}
|
||||
|
||||
TEST_CASE("call decode_varint with every possible value for single byte in buffer") {
|
||||
char buffer[1];
|
||||
for (unsigned int i = 0; i <= 127; ++i) {
|
||||
REQUIRE(protozero::length_of_varint(i) == 1);
|
||||
buffer[0] = static_cast<char>(i);
|
||||
const char* b = buffer;
|
||||
REQUIRE(protozero::decode_varint(&b, buffer + 1) == i);
|
||||
REQUIRE(b == buffer + 1);
|
||||
}
|
||||
for (unsigned int i = 128; i <= 255; ++i) {
|
||||
REQUIRE(protozero::length_of_varint(i) == 2);
|
||||
buffer[0] = static_cast<char>(i);
|
||||
const char* b = buffer;
|
||||
REQUIRE_THROWS_AS(protozero::decode_varint(&b, buffer + 1), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("check lengths of varint") {
|
||||
REQUIRE(protozero::length_of_varint(0) == 1);
|
||||
REQUIRE(protozero::length_of_varint(127) == 1);
|
||||
REQUIRE(protozero::length_of_varint(128) == 2);
|
||||
REQUIRE(protozero::length_of_varint(16383) == 2);
|
||||
REQUIRE(protozero::length_of_varint(16384) == 3);
|
||||
REQUIRE(protozero::length_of_varint(2097151) == 3);
|
||||
REQUIRE(protozero::length_of_varint(2097152) == 4);
|
||||
REQUIRE(protozero::length_of_varint(0xffffffffULL) == 5);
|
||||
REQUIRE(protozero::length_of_varint(0xffffffffffffffffULL) == 10);
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -22,22 +22,28 @@ static_assert(protozero::decode_zigzag32(1UL) == -1L, "test constexpr zigzag fun
|
||||
static_assert(protozero::decode_zigzag32(2UL) == 1L, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag32(3UL) == -2L, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag32(4UL) == 2L, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag32(0xfffffffeUL) == 0x7fffffffL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag32(0xfffffffdUL) == -0x7fffffffL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag32(2 * static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ) == std::numeric_limits<int32_t>::max(), "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag32(2 * static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) - 1) == -std::numeric_limits<int32_t>::max(), "test constexpr zigzag functions");
|
||||
|
||||
// fails on Visual Studio 2017
|
||||
//static_assert(protozero::decode_zigzag32(2 * static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) - 1) == -std::numeric_limits<int32_t>::max(), "test constexpr zigzag functions");
|
||||
|
||||
static_assert(protozero::decode_zigzag64(0ULL) == 0LL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag64(1ULL) == -1LL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag64(2ULL) == 1LL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag64(3ULL) == -2LL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag64(4ULL) == 2LL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag64(0xfffffffffffffffeULL) == 0x7fffffffffffffffLL, "test constexpr zigzag functions");
|
||||
static_assert(protozero::decode_zigzag64(0xfffffffffffffffdULL) == -0x7fffffffffffffffLL, "test constexpr zigzag functions");
|
||||
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) {
|
||||
inline constexpr int32_t zz32(int32_t val) noexcept {
|
||||
return protozero::decode_zigzag32(protozero::encode_zigzag32(val));
|
||||
}
|
||||
|
||||
inline constexpr int64_t zz64(int64_t val) {
|
||||
inline constexpr int64_t zz64(int64_t val) noexcept {
|
||||
return protozero::decode_zigzag64(protozero::encode_zigzag64(val));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user