Bump version of protozero to 1.7.1 (#6999)
This commit is contained in:
parent
09a716a9e5
commit
4f1c62a768
@ -22,7 +22,7 @@ MICROTAR_PATH="rxi/microtar"
|
||||
MICROTAR_TAG=v0.1.0
|
||||
|
||||
PROTOZERO_PATH="mapbox/protozero"
|
||||
PROTOZERO_TAG=v1.6.2
|
||||
PROTOZERO_TAG=v1.7.1
|
||||
|
||||
VTZERO_PATH="mapbox/vtzero"
|
||||
VTZERO_TAG=v1.1.0
|
||||
|
24
third_party/protozero/.clang-tidy
vendored
24
third_party/protozero/.clang-tidy
vendored
@ -1,8 +1,15 @@
|
||||
---
|
||||
Checks: '*,-bugprone-signed-char-misuse,-cert-dcl21-cpp,-cert-err58-cpp,-cert-err60-cpp,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-macro-usage,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-reinterpret-cast,-fuchsia-*,-google-runtime-references,-hicpp-avoid-c-arrays,-hicpp-no-array-decay,-hicpp-vararg,-modernize-avoid-c-arrays,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-magic-numbers'
|
||||
Checks: '*,-altera-*,-bugprone-easily-swappable-parameters,-bugprone-signed-char-misuse,-cert-dcl21-cpp,-cert-err58-cpp,-cert-err60-cpp,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-macro-usage,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-reinterpret-cast,-fuchsia-*,-google-runtime-references,-hicpp-avoid-c-arrays,-hicpp-no-array-decay,-hicpp-vararg,-llvmlibc-*,-misc-no-recursion,-modernize-avoid-c-arrays,-modernize-use-trailing-return-type,-readability-function-cognitive-complexity,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-magic-numbers'
|
||||
#
|
||||
# Disabled checks:
|
||||
#
|
||||
# altera-*
|
||||
# Doesn't apply.
|
||||
#
|
||||
# bugprone-easily-swappable-parameters
|
||||
# Can't change this any more, because these functions are part of our public
|
||||
# interface.
|
||||
#
|
||||
# bugprone-signed-char-misuse
|
||||
# Lots of warnings in varint.hpp otherwise.
|
||||
#
|
||||
@ -25,6 +32,9 @@ Checks: '*,-bugprone-signed-char-misuse,-cert-dcl21-cpp,-cert-err58-cpp,-cert-er
|
||||
# readability-magic-numbers
|
||||
# Good idea, but it goes too far to force this everywhere.
|
||||
#
|
||||
# cppcoreguidelines-avoid-non-const-global-variables
|
||||
# Getting these from Catch2 test framework, not from the code itself.
|
||||
#
|
||||
# cppcoreguidelines-macro-usage
|
||||
# There are cases where macros are simply needed.
|
||||
#
|
||||
@ -47,9 +57,21 @@ Checks: '*,-bugprone-signed-char-misuse,-cert-dcl21-cpp,-cert-err58-cpp,-cert-er
|
||||
# hicpp-no-array-decay
|
||||
# Limited use and many false positives including for all asserts.
|
||||
#
|
||||
# llvmlibc-*
|
||||
# Doesn't apply.
|
||||
#
|
||||
# misc-no-recursion
|
||||
# Nothing wrong with recursion.
|
||||
#
|
||||
# modernize-use-trailing-return-type
|
||||
# We are not quite that modern.
|
||||
#
|
||||
# readability-function-cognitive-complexity
|
||||
# Getting these mostly from Catch2 test framework.
|
||||
#
|
||||
# readability-identifier-length
|
||||
# Short identifiers do make sense sometimes.
|
||||
#
|
||||
# readability-implicit-bool-conversion
|
||||
# Not necessarily more readable.
|
||||
#
|
||||
|
25
third_party/protozero/CHANGELOG.md
vendored
25
third_party/protozero/CHANGELOG.md
vendored
@ -2,8 +2,8 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
||||
This project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [unreleased] -
|
||||
|
||||
@ -14,6 +14,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
### Fixed
|
||||
|
||||
|
||||
## [1.7.1] - 2022-01-10
|
||||
|
||||
### Changed
|
||||
|
||||
- Don't build tests if the standard CMake `BUILD_TESTING` variable is set to
|
||||
off.
|
||||
- Now needs CMake 3.5.0 or greater.
|
||||
- Update included catch2 framework to current version v2.13.8.
|
||||
- Only enable clang-tidy make target if protobuf was found.
|
||||
- Allow setting C++ version to compile with in CMake config.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixes undefined behaviour in `float` and `double` byteswap.
|
||||
- Add missing includes of "config.hpp".
|
||||
- Avoid narrowing conversion by doing an explicit `static_cast`.
|
||||
|
||||
|
||||
## [1.7.0] - 2020-06-08
|
||||
|
||||
### Added
|
||||
@ -381,7 +399,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Make pbf reader and writer code endianess-aware.
|
||||
|
||||
|
||||
[unreleased]: https://github.com/osmcode/libosmium/compare/v1.7.0...HEAD
|
||||
[unreleased]: https://github.com/osmcode/libosmium/compare/v1.7.1...HEAD
|
||||
[1.7.1]: https://github.com/osmcode/libosmium/compare/v1.7.0...v1.7.1
|
||||
[1.7.0]: https://github.com/osmcode/libosmium/compare/v1.6.8...v1.7.0
|
||||
[1.6.8]: https://github.com/osmcode/libosmium/compare/v1.6.7...v1.6.8
|
||||
[1.6.7]: https://github.com/osmcode/libosmium/compare/v1.6.6...v1.6.7
|
||||
|
41
third_party/protozero/CMakeLists.txt
vendored
41
third_party/protozero/CMakeLists.txt
vendored
@ -6,32 +6,35 @@
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
project(protozero)
|
||||
|
||||
set(PROTOZERO_VERSION_MAJOR 1)
|
||||
set(PROTOZERO_VERSION_MINOR 7)
|
||||
set(PROTOZERO_VERSION_PATCH 0)
|
||||
|
||||
set(PROTOZERO_VERSION
|
||||
"${PROTOZERO_VERSION_MAJOR}.${PROTOZERO_VERSION_MINOR}.${PROTOZERO_VERSION_PATCH}")
|
||||
project(protozero VERSION 1.7.1 LANGUAGES CXX C)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if (NOT "${CMAKE_CXX_STANDARD}")
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
endif()
|
||||
message(STATUS "Building in C++${CMAKE_CXX_STANDARD} mode")
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
option(BUILD_TESTING "Build tests" ON)
|
||||
option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON)
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(/W3)
|
||||
add_compile_options(/W3)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
add_definitions(-std=c++11 -Wall -Wextra -pedantic -Wsign-compare -Wunused-parameter -Wno-float-equal -Wno-covered-switch-default)
|
||||
add_compile_options(-Wall -Wextra -pedantic -Wsign-compare -Wunused-parameter -Wno-float-equal -Wno-covered-switch-default)
|
||||
if(WERROR)
|
||||
add_definitions(-Werror)
|
||||
add_compile_options(-Werror)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -58,9 +61,9 @@ find_package(Protobuf)
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
message(STATUS "Looking for clang-tidy")
|
||||
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-10 clang-tidy-9 clang-tidy-8 clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0)
|
||||
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11)
|
||||
|
||||
if(CLANG_TIDY)
|
||||
if(CLANG_TIDY AND PROTOBUF_FOUND)
|
||||
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
|
||||
add_custom_target(clang-tidy
|
||||
${CLANG_TIDY}
|
||||
@ -134,13 +137,13 @@ install(DIRECTORY include/protozero DESTINATION include)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory(doc)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
add_subdirectory(tools)
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
2
third_party/protozero/FUZZING.md
vendored
2
third_party/protozero/FUZZING.md
vendored
@ -1,5 +1,5 @@
|
||||
|
||||
To do fuzz testing using [AFL](http://lcamtuf.coredump.cx/afl/) compile with
|
||||
To do fuzz testing using [AFL](https://lcamtuf.coredump.cx/afl/) compile with
|
||||
the AFL compiler wrappers:
|
||||
|
||||
mkdir build
|
||||
|
4
third_party/protozero/README.md
vendored
4
third_party/protozero/README.md
vendored
@ -11,7 +11,7 @@ changing frequently or lazy decoding is not critical for your application then
|
||||
this approach offers no value: just use the C++ API that can be generated with
|
||||
the Google Protobufs `protoc` program.
|
||||
|
||||
[](https://travis-ci.org/mapbox/protozero)
|
||||
[](https://travis-ci.com/mapbox/protozero)
|
||||
[](https://ci.appveyor.com/project/Mapbox/protozero)
|
||||
[](https://codecov.io/gh/mapbox/protozero)
|
||||
[](https://repology.org/metapackage/protozero)
|
||||
@ -123,7 +123,7 @@ You might have to set `CLANG_TIDY` in CMake config.
|
||||
|
||||
## Cppcheck
|
||||
|
||||
For extra checks with [Cppcheck](http://cppcheck.sourceforge.net/) you can,
|
||||
For extra checks with [Cppcheck](https://cppcheck.sourceforge.io/) you can,
|
||||
after the CMake step, call
|
||||
|
||||
make cppcheck
|
||||
|
5
third_party/protozero/appveyor.yml
vendored
5
third_party/protozero/appveyor.yml
vendored
@ -14,8 +14,6 @@ clone_depth: 1
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- config: MSYS2
|
||||
autocrlf: true
|
||||
- config: Debug
|
||||
autocrlf: true
|
||||
- config: RelWithDebInfo
|
||||
@ -27,6 +25,9 @@ environment:
|
||||
- config: Debug
|
||||
autocrlf: false
|
||||
platform: x86
|
||||
- config: MSYS2
|
||||
autocrlf: true
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
|
2
third_party/protozero/bench/data/README.md
vendored
2
third_party/protozero/bench/data/README.md
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
mapbox-streets-v6/14/8714/8017.vector.pbf
|
||||
|
||||
- http://c.tile.openstreetmap.org/14/8714/8017.png
|
||||
- https://c.tile.openstreetmap.org/14/8714/8017.png
|
||||
- https://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/14/8714/8017.vector.pbf
|
||||
- https://www.mapbox.com/developers/vector-tiles/mapbox-streets/
|
||||
|
||||
|
683
third_party/protozero/doc/Doxyfile.in
vendored
683
third_party/protozero/doc/Doxyfile.in
vendored
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@ documentation.
|
||||
*/
|
||||
|
||||
#include "buffer_tmpl.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
@ -56,7 +57,8 @@ struct buffer_customization<std::string> {
|
||||
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));
|
||||
buffer->erase(std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(from)),
|
||||
std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(to)));
|
||||
}
|
||||
|
||||
static char* at_pos(std::string* buffer, std::size_t pos) {
|
||||
|
@ -18,6 +18,7 @@ documentation.
|
||||
*/
|
||||
|
||||
#include "buffer_tmpl.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
@ -56,7 +57,8 @@ struct buffer_customization<std::vector<char>> {
|
||||
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));
|
||||
buffer->erase(std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(from)),
|
||||
std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(to)));
|
||||
}
|
||||
|
||||
static char* at_pos(std::vector<char>* buffer, std::size_t pos) {
|
||||
|
@ -19,6 +19,7 @@ documentation.
|
||||
#include "config.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace protozero {
|
||||
namespace detail {
|
||||
@ -75,14 +76,22 @@ inline void byteswap_inplace(int64_t* ptr) noexcept {
|
||||
|
||||
/// byteswap the data pointed to by ptr in-place.
|
||||
inline void byteswap_inplace(float* ptr) noexcept {
|
||||
auto* bptr = reinterpret_cast<uint32_t*>(ptr);
|
||||
*bptr = detail::byteswap_impl(*bptr);
|
||||
static_assert(sizeof(float) == 4, "Expecting four byte float");
|
||||
|
||||
uint32_t tmp = 0;
|
||||
std::memcpy(&tmp, ptr, 4);
|
||||
tmp = detail::byteswap_impl(tmp); // uint32 overload
|
||||
std::memcpy(ptr, &tmp, 4);
|
||||
}
|
||||
|
||||
/// byteswap the data pointed to by ptr in-place.
|
||||
inline void byteswap_inplace(double* ptr) noexcept {
|
||||
auto* bptr = reinterpret_cast<uint64_t*>(ptr);
|
||||
*bptr = detail::byteswap_impl(*bptr);
|
||||
static_assert(sizeof(double) == 8, "Expecting eight byte double");
|
||||
|
||||
uint64_t tmp = 0;
|
||||
std::memcpy(&tmp, ptr, 8);
|
||||
tmp = detail::byteswap_impl(tmp); // uint64 overload
|
||||
std::memcpy(ptr, &tmp, 8);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
@ -23,12 +23,12 @@ documentation.
|
||||
#define PROTOZERO_VERSION_MINOR 7
|
||||
|
||||
/// The patch number
|
||||
#define PROTOZERO_VERSION_PATCH 0
|
||||
#define PROTOZERO_VERSION_PATCH 1
|
||||
|
||||
/// The complete version number
|
||||
#define PROTOZERO_VERSION_CODE (PROTOZERO_VERSION_MAJOR * 10000 + PROTOZERO_VERSION_MINOR * 100 + PROTOZERO_VERSION_PATCH)
|
||||
|
||||
/// Version number as string
|
||||
#define PROTOZERO_VERSION_STRING "1.7.0"
|
||||
#define PROTOZERO_VERSION_STRING "1.7.1"
|
||||
|
||||
#endif // PROTOZERO_VERSION_HPP
|
||||
|
116
third_party/protozero/test/CMakeLists.txt
vendored
116
third_party/protozero/test/CMakeLists.txt
vendored
@ -1,116 +0,0 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# CMake config
|
||||
#
|
||||
# protozero tests
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/catch")
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
add_subdirectory(unit)
|
||||
|
||||
set(TEST_DIRS alignment
|
||||
bool
|
||||
bytes
|
||||
complex
|
||||
double
|
||||
enum
|
||||
fixed32
|
||||
fixed64
|
||||
float
|
||||
int32
|
||||
int64
|
||||
message
|
||||
nested
|
||||
repeated
|
||||
repeated_packed_bool
|
||||
repeated_packed_double
|
||||
repeated_packed_enum
|
||||
repeated_packed_fixed32
|
||||
repeated_packed_fixed64
|
||||
repeated_packed_float
|
||||
repeated_packed_int32
|
||||
repeated_packed_int64
|
||||
repeated_packed_sfixed32
|
||||
repeated_packed_sfixed64
|
||||
repeated_packed_sint32
|
||||
repeated_packed_sint64
|
||||
repeated_packed_uint32
|
||||
repeated_packed_uint64
|
||||
rollback
|
||||
sfixed32
|
||||
sfixed64
|
||||
sint32
|
||||
sint64
|
||||
skip
|
||||
string
|
||||
tag_and_type
|
||||
tags
|
||||
uint32
|
||||
uint64
|
||||
vector_tile
|
||||
wrong_type_access)
|
||||
|
||||
string(REGEX REPLACE "([^;]+)" "t/\\1/reader_test_cases.cpp" _test_sources "${TEST_DIRS}")
|
||||
|
||||
add_executable(reader_tests reader_tests.cpp ${_test_sources})
|
||||
|
||||
add_test(NAME reader_tests COMMAND reader_tests)
|
||||
|
||||
set_tests_properties(reader_tests PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
|
||||
|
||||
if(PROTOBUF_FOUND)
|
||||
message(STATUS "Found protobuf libraries: Adding writer tests...")
|
||||
|
||||
include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(PROTOBUF_GENERATE_CPP_APPEND_PATH false)
|
||||
|
||||
foreach(_dir IN LISTS TEST_DIRS)
|
||||
set(_full_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/t/${_dir}")
|
||||
if(EXISTS "${_full_src_dir}/writer_test_cases.cpp")
|
||||
message(STATUS " Adding ${_dir}")
|
||||
set(_full_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/t/${_dir}")
|
||||
set(_proto_file "${_full_src_dir}/${_dir}_testcase.proto")
|
||||
set(_src_file "${_full_bin_dir}/${_dir}_testcase.pb.cc")
|
||||
set(_hdr_file "${_full_bin_dir}/${_dir}_testcase.pb.h")
|
||||
|
||||
file(MAKE_DIRECTORY ${_full_bin_dir})
|
||||
|
||||
list(APPEND SOURCES "${_full_src_dir}/writer_test_cases.cpp")
|
||||
list(APPEND PROTO_FILES "${_proto_file}")
|
||||
list(APPEND PROTO_SRCS "${_src_file}")
|
||||
list(APPEND PROTO_HDRS "${_hdr_file}")
|
||||
|
||||
set_source_files_properties(${_proto_file} ${_hdr_file}
|
||||
PROPERTIES GENERATED TRUE)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${_src_file} ${_hdr_file}
|
||||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
|
||||
ARGS --cpp_out=${_full_bin_dir} -I ${_full_src_dir} ${_proto_file}
|
||||
DEPENDS ${_proto_file}
|
||||
VERBATIM)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_executable(writer_tests writer_tests.cpp ${SOURCES} ${PROTO_SRCS} ${PROTO_HDRS})
|
||||
|
||||
target_link_libraries(writer_tests ${PROTOBUF_LITE_LIBRARY})
|
||||
|
||||
if(NOT MSVC)
|
||||
set_target_properties(writer_tests PROPERTIES COMPILE_FLAGS "-pthread")
|
||||
if(NOT APPLE)
|
||||
set_target_properties(writer_tests PROPERTIES LINK_FLAGS "-pthread")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test(NAME writer_tests COMMAND writer_tests)
|
||||
else()
|
||||
message(STATUS "Protobuf libraries not found: Disabling writer tests.")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
52
third_party/protozero/test/README.md
vendored
52
third_party/protozero/test/README.md
vendored
@ -1,52 +0,0 @@
|
||||
|
||||
# Tests
|
||||
|
||||
Tests are using the [Catch Unit Test Framework](https://github.com/philsquared/Catch).
|
||||
|
||||
## Organization of the unit tests
|
||||
|
||||
Unit tests test low-level functions of the library. They are in the `unit`
|
||||
directory.
|
||||
|
||||
|
||||
## Organization of the reader/writer test cases
|
||||
|
||||
The hart of the tests are the reader/writer tests checking all aspects of
|
||||
decoding and encoding protobuf files.
|
||||
|
||||
Each test case is in its own directory under the `t` directory. Each directory
|
||||
contains (some of) the following files:
|
||||
|
||||
* `reader_test_cases.cpp`: The C++ source code that runs the reader tests.
|
||||
* `writer_test_cases.cpp`: The C++ source code that runs the writer tests.
|
||||
* `data-*.pbf`: PBF data files used by the tests.
|
||||
* `testcase.proto`: Protobuf file describing the format of the data files.
|
||||
* `testcase.cpp`: C++ file for creating the data files.
|
||||
|
||||
### Reader tests
|
||||
|
||||
The CMake config finds all the `reader_test_cases.cpp` files and compiles them.
|
||||
Together with the `reader_tests.cpp` file they make up the `reader_tests`
|
||||
executable which can be called to execute all the reader tests.
|
||||
|
||||
### Extra writer tests
|
||||
|
||||
The CMake config finds all the `writer_test_cases.cpp` files and compiles them.
|
||||
Together with the `writer_tests.cpp` file they make up the `writer_tests`
|
||||
executable which can be called to execute all the writer tests.
|
||||
|
||||
The writer tests need the Google protobuf library to work.
|
||||
|
||||
|
||||
## Creating test data from scratch
|
||||
|
||||
Most tests use test data stored in PBF format in their directory. The files
|
||||
have the suffix `.pbf`. Most of those files have been generated from the
|
||||
provided `testcase.proto` and `testcase.cpp` files.
|
||||
|
||||
Usually you do not have to do this, but if you want to re-generate the PBF
|
||||
data files, you can do so:
|
||||
|
||||
cd test
|
||||
./create_pbf_test_data.sh
|
||||
|
17698
third_party/protozero/test/catch/catch.hpp
vendored
17698
third_party/protozero/test/catch/catch.hpp
vendored
File diff suppressed because it is too large
Load Diff
@ -1,35 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# create_pbf_test_data.sh [TESTCASE]
|
||||
#
|
||||
# This script creates the test data for the given test case in protobuf format
|
||||
# using the testcase.proto description and the testcase.cpp code.
|
||||
#
|
||||
# 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
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Generating $1..."
|
||||
cd $1
|
||||
if [ -f testcase.proto ]; then
|
||||
protoc --cpp_out=. testcase.proto
|
||||
$CXX -std=c++11 -I../../include -o testcase testcase.cpp testcase.pb.cc -lprotobuf-lite -pthread
|
||||
./testcase
|
||||
fi
|
||||
cd ../..
|
||||
|
162
third_party/protozero/test/include/buffer.hpp
vendored
162
third_party/protozero/test/include/buffer.hpp
vendored
@ -1,162 +0,0 @@
|
||||
#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
|
305
third_party/protozero/test/include/packed_access.hpp
vendored
305
third_party/protozero/test/include/packed_access.hpp
vendored
@ -1,305 +0,0 @@
|
||||
// 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)
|
||||
|
||||
using packed_field_type = PROTOZERO_TEST_CONCAT(protozero::packed_field_, PBF_TYPE);
|
||||
|
||||
TEST_CASE("read repeated packed field: " PBF_TYPE_NAME) {
|
||||
// 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
|
||||
// is aligned before that, in at least one of these cases the ints will
|
||||
// not be aligned properly. So we test that even in that case the ints
|
||||
// will be extracted properly.
|
||||
|
||||
for (std::string::size_type n = 0; n < 2; ++n) {
|
||||
std::string abuffer;
|
||||
abuffer.reserve(1000);
|
||||
abuffer.append(n, '\0');
|
||||
|
||||
SECTION("empty") {
|
||||
abuffer.append(load_data("repeated_packed_" PBF_TYPE_NAME "/data-empty"));
|
||||
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
abuffer.append(load_data("repeated_packed_" PBF_TYPE_NAME "/data-one"));
|
||||
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
const auto it_range = item.GET_TYPE();
|
||||
REQUIRE_FALSE(item.next());
|
||||
|
||||
REQUIRE(it_range.begin() != it_range.end());
|
||||
REQUIRE(*it_range.begin() == 17);
|
||||
REQUIRE(std::next(it_range.begin()) == it_range.end());
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
abuffer.append(load_data("repeated_packed_" PBF_TYPE_NAME "/data-many"));
|
||||
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
const auto it_range = item.GET_TYPE();
|
||||
REQUIRE_FALSE(item.next());
|
||||
|
||||
auto it = it_range.begin();
|
||||
REQUIRE(it != it_range.end());
|
||||
REQUIRE(*it++ == 17);
|
||||
REQUIRE(*it++ == 200);
|
||||
REQUIRE(*it++ == 0);
|
||||
REQUIRE(*it++ == 1);
|
||||
REQUIRE(*it++ == std::numeric_limits<cpp_type>::max());
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
REQUIRE(*it++ == -200);
|
||||
REQUIRE(*it++ == -1);
|
||||
REQUIRE(*it++ == std::numeric_limits<cpp_type>::min());
|
||||
#endif
|
||||
REQUIRE(it == it_range.end());
|
||||
}
|
||||
|
||||
SECTION("swap iterator range") {
|
||||
abuffer.append(load_data("repeated_packed_" PBF_TYPE_NAME "/data-many"));
|
||||
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
auto it_range1 = item.GET_TYPE();
|
||||
REQUIRE_FALSE(item.next());
|
||||
|
||||
decltype(it_range1) it_range;
|
||||
using std::swap;
|
||||
swap(it_range, it_range1);
|
||||
|
||||
auto it = it_range.begin();
|
||||
REQUIRE(it != it_range.end());
|
||||
REQUIRE(*it++ == 17);
|
||||
REQUIRE(*it++ == 200);
|
||||
REQUIRE(*it++ == 0);
|
||||
REQUIRE(*it++ == 1);
|
||||
REQUIRE(*it++ == std::numeric_limits<cpp_type>::max());
|
||||
}
|
||||
|
||||
SECTION("end_of_buffer") {
|
||||
abuffer.append(load_data("repeated_packed_" PBF_TYPE_NAME "/data-many"));
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("write repeated packed field: " PBF_TYPE_NAME) {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
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") {
|
||||
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") {
|
||||
std::array<cpp_type,
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
8
|
||||
#else
|
||||
5
|
||||
#endif
|
||||
> data = {{
|
||||
17
|
||||
, 200
|
||||
, 0
|
||||
, 1
|
||||
,std::numeric_limits<cpp_type>::max()
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
,-200
|
||||
, -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("write repeated packed field using packed field: " PBF_TYPE_NAME) {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty - should do rollback") {
|
||||
{
|
||||
packed_field_type field{pw, 1};
|
||||
}
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
{
|
||||
packed_field_type field{pw, 1};
|
||||
field.add_element(cpp_type(17));
|
||||
}
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-one"));
|
||||
}
|
||||
|
||||
SECTION("many") {
|
||||
{
|
||||
packed_field_type field{pw, 1};
|
||||
field.add_element(cpp_type( 17));
|
||||
field.add_element(cpp_type( 200));
|
||||
field.add_element(cpp_type( 0));
|
||||
field.add_element(cpp_type( 1));
|
||||
field.add_element(std::numeric_limits<cpp_type>::max());
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
field.add_element(cpp_type(-200));
|
||||
field.add_element(cpp_type( -1));
|
||||
field.add_element(std::numeric_limits<cpp_type>::min());
|
||||
#endif
|
||||
REQUIRE(field.valid());
|
||||
SECTION("with commit") {
|
||||
field.commit();
|
||||
REQUIRE_FALSE(field.valid());
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-many"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("move repeated packed field: " PBF_TYPE_NAME) {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("move rvalue") {
|
||||
packed_field_type field;
|
||||
REQUIRE_FALSE(field.valid());
|
||||
field = packed_field_type{pw, 1};
|
||||
REQUIRE(field.valid());
|
||||
field.add_element(cpp_type(17));
|
||||
}
|
||||
|
||||
SECTION("explicit move") {
|
||||
packed_field_type field2{pw, 1};
|
||||
packed_field_type field;
|
||||
|
||||
REQUIRE(field2.valid());
|
||||
REQUIRE_FALSE(field.valid());
|
||||
|
||||
field = std::move(field2);
|
||||
|
||||
REQUIRE_FALSE(field2.valid()); // NOLINT(hicpp-invalid-access-moved, bugprone-use-after-move)
|
||||
REQUIRE(field.valid());
|
||||
|
||||
field.add_element(cpp_type(17));
|
||||
}
|
||||
|
||||
SECTION("move constructor") {
|
||||
packed_field_type field2{pw, 1};
|
||||
REQUIRE(field2.valid());
|
||||
|
||||
packed_field_type field{std::move(field2)};
|
||||
REQUIRE(field.valid());
|
||||
REQUIRE_FALSE(field2.valid()); // NOLINT(hicpp-invalid-access-moved, bugprone-use-after-move)
|
||||
|
||||
field.add_element(cpp_type(17));
|
||||
}
|
||||
|
||||
SECTION("swap") {
|
||||
packed_field_type field;
|
||||
packed_field_type field2{pw, 1};
|
||||
|
||||
REQUIRE_FALSE(field.valid());
|
||||
REQUIRE(field2.valid());
|
||||
|
||||
using std::swap;
|
||||
swap(field, field2);
|
||||
|
||||
REQUIRE(field.valid());
|
||||
REQUIRE_FALSE(field2.valid());
|
||||
|
||||
field.add_element(cpp_type(17));
|
||||
}
|
||||
|
||||
REQUIRE(buffer == load_data("repeated_packed_" PBF_TYPE_NAME "/data-one"));
|
||||
}
|
||||
|
||||
TEST_CASE("write from different types of iterators: " PBF_TYPE_NAME) {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("from uint16_t") {
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
const std::array< int16_t, 5> data = {{ 1, 4, 9, 16, 25 }};
|
||||
#else
|
||||
const std::array<uint16_t, 5> data = {{ 1, 4, 9, 16, 25 }};
|
||||
#endif
|
||||
|
||||
pw.ADD_TYPE(1, std::begin(data), std::end(data));
|
||||
}
|
||||
|
||||
SECTION("from string") {
|
||||
std::string data{"1 4 9 16 25"};
|
||||
std::stringstream sdata{data};
|
||||
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
using test_type = int32_t;
|
||||
#else
|
||||
using test_type = uint32_t;
|
||||
#endif
|
||||
|
||||
std::istream_iterator<test_type> eod;
|
||||
std::istream_iterator<test_type> it(sdata);
|
||||
|
||||
pw.ADD_TYPE(1, it, eod);
|
||||
}
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
auto it_range = item.GET_TYPE();
|
||||
REQUIRE_FALSE(item.next());
|
||||
REQUIRE_FALSE(it_range.empty());
|
||||
REQUIRE(std::distance(it_range.begin(), it_range.end()) == 5);
|
||||
REQUIRE(it_range.size() == 5);
|
||||
|
||||
REQUIRE(it_range.front() == 1); it_range.drop_front();
|
||||
REQUIRE(it_range.front() == 4); it_range.drop_front();
|
||||
REQUIRE(std::distance(it_range.begin(), it_range.end()) == 3);
|
||||
REQUIRE(it_range.size() == 3);
|
||||
REQUIRE(it_range.front() == 9); it_range.drop_front();
|
||||
REQUIRE(it_range.front() == 16); it_range.drop_front();
|
||||
REQUIRE(it_range.front() == 25); it_range.drop_front();
|
||||
REQUIRE(it_range.empty());
|
||||
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(), assert_error);
|
||||
REQUIRE_THROWS_AS(it_range.drop_front(), assert_error);
|
||||
}
|
||||
|
129
third_party/protozero/test/include/scalar_access.hpp
vendored
129
third_party/protozero/test/include/scalar_access.hpp
vendored
@ -1,129 +0,0 @@
|
||||
// NOLINT(llvm-header-guard)
|
||||
|
||||
#define PBF_TYPE_NAME PROTOZERO_TEST_STRING(PBF_TYPE)
|
||||
#define GET_TYPE PROTOZERO_TEST_CONCAT(get_, PBF_TYPE)
|
||||
#define ADD_TYPE PROTOZERO_TEST_CONCAT(add_, PBF_TYPE)
|
||||
|
||||
TEST_CASE("read field: " PBF_TYPE_NAME) {
|
||||
|
||||
SECTION("zero") {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-zero");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == 0);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-pos");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == 1);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("pos200") {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-pos200");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == 200);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-max");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == std::numeric_limits<cpp_type>::max());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
SECTION("negative") {
|
||||
if (std::is_signed<cpp_type>::value) {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-neg");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == -1);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("neg200") {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-neg200");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == -200);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("min") {
|
||||
if (std::is_signed<cpp_type>::value) {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-min");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.GET_TYPE() == std::numeric_limits<cpp_type>::min());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("end_of_buffer") {
|
||||
const std::string buffer = load_data(PBF_TYPE_NAME "/data-max");
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write field: " PBF_TYPE_NAME) {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw(buffer);
|
||||
|
||||
SECTION("zero") {
|
||||
pw.ADD_TYPE(1, 0);
|
||||
REQUIRE(buffer == load_data(PBF_TYPE_NAME "/data-zero"));
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.ADD_TYPE(1, 1);
|
||||
REQUIRE(buffer == load_data(PBF_TYPE_NAME "/data-pos"));
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
pw.ADD_TYPE(1, std::numeric_limits<cpp_type>::max());
|
||||
REQUIRE(buffer == load_data(PBF_TYPE_NAME "/data-max"));
|
||||
}
|
||||
|
||||
#if PBF_TYPE_IS_SIGNED
|
||||
SECTION("negative") {
|
||||
pw.ADD_TYPE(1, -1);
|
||||
REQUIRE(buffer == load_data(PBF_TYPE_NAME "/data-neg"));
|
||||
}
|
||||
|
||||
SECTION("min") {
|
||||
if (std::is_signed<cpp_type>::value) {
|
||||
pw.ADD_TYPE(1, std::numeric_limits<cpp_type>::min());
|
||||
REQUIRE(buffer == load_data(PBF_TYPE_NAME "/data-min"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
31
third_party/protozero/test/include/test.hpp
vendored
31
third_party/protozero/test/include/test.hpp
vendored
@ -1,31 +0,0 @@
|
||||
#ifndef TEST_HPP
|
||||
#define TEST_HPP
|
||||
|
||||
#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.
|
||||
struct assert_error : public std::runtime_error {
|
||||
explicit assert_error(const char* what_arg) : std::runtime_error(what_arg) {
|
||||
}
|
||||
};
|
||||
#define protozero_assert(x) if (!(x)) { throw assert_error{#x}; }
|
||||
|
||||
#include <protozero/pbf_builder.hpp>
|
||||
#include <protozero/pbf_message.hpp>
|
||||
#include <protozero/pbf_reader.hpp>
|
||||
#include <protozero/pbf_writer.hpp>
|
||||
|
||||
extern std::string load_data(const std::string& filename);
|
||||
|
||||
#define PROTOZERO_TEST_CONCAT2(x, y) x##y
|
||||
#define PROTOZERO_TEST_CONCAT(x, y) PROTOZERO_TEST_CONCAT2(x, y)
|
||||
|
||||
#define PROTOZERO_TEST_STRING2(s) #s
|
||||
#define PROTOZERO_TEST_STRING(s) PROTOZERO_TEST_STRING2(s)
|
||||
|
||||
#endif // TEST_HPP
|
21
third_party/protozero/test/include/testcase.hpp
vendored
21
third_party/protozero/test/include/testcase.hpp
vendored
@ -1,21 +0,0 @@
|
||||
#ifndef TESTCASE_HPP
|
||||
#define TESTCASE_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
template <class T>
|
||||
std::string write_to_file(const T& msg, const char* filename) {
|
||||
std::string out;
|
||||
|
||||
msg.SerializeToString(&out);
|
||||
std::ofstream d{filename, std::ios_base::out|std::ios_base::binary};
|
||||
assert(d.is_open());
|
||||
d << out;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif // TESTCASE_HPP
|
32
third_party/protozero/test/reader_tests.cpp
vendored
32
third_party/protozero/test/reader_tests.cpp
vendored
@ -1,32 +0,0 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <test.hpp> // IWYU pragma: keep
|
||||
|
||||
std::string load_data(const std::string& filename) {
|
||||
const char* tests_dir = std::getenv("TESTS_DIR");
|
||||
if (tests_dir == nullptr) {
|
||||
tests_dir = "test";
|
||||
}
|
||||
|
||||
std::string fullname{tests_dir};
|
||||
fullname += "/t/";
|
||||
fullname += filename;
|
||||
fullname += ".pbf";
|
||||
|
||||
std::ifstream stream{fullname, std::ios_base::in | std::ios_base::binary};
|
||||
if (!stream.is_open()) {
|
||||
throw std::runtime_error{"could not open: '" + filename + "'"};
|
||||
}
|
||||
std::string buffer{std::istreambuf_iterator<char>(stream.rdbuf()),
|
||||
std::istreambuf_iterator<char>()};
|
||||
stream.close();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
// 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
|
||||
// is aligned before that, in at least one of these cases the int32 will
|
||||
// not be aligned properly. So we test that even in that case the int32
|
||||
// will be extracted properly.
|
||||
|
||||
TEST_CASE("check alignment issues for fixed32 field") {
|
||||
for (std::string::size_type n = 0; n < 2; ++n) {
|
||||
|
||||
std::string abuffer;
|
||||
abuffer.reserve(1000);
|
||||
abuffer.append(n, '\0');
|
||||
|
||||
SECTION("zero") {
|
||||
abuffer.append(load_data("fixed32/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed32() == 0UL);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
abuffer.append(load_data("fixed32/data-pos"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed32() == 1UL);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
abuffer.append(load_data("fixed32/data-max"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed32() == std::numeric_limits<uint32_t>::max());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("end_of_buffer") {
|
||||
abuffer.append(load_data("fixed32/data-pos"));
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("assert detecting tag==0") {
|
||||
abuffer.append(load_data("fixed32/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE_THROWS_AS(item.get_fixed32(), assert_error);
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed32() == 0UL);
|
||||
REQUIRE_THROWS(item.get_fixed32());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("skip") {
|
||||
abuffer.append(load_data("fixed32/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE_THROWS_AS(item.skip(), assert_error);
|
||||
REQUIRE(item.next());
|
||||
item.skip();
|
||||
REQUIRE_THROWS(item.skip());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("check alignment issues for fixed64 field") {
|
||||
for (std::string::size_type n = 0; n < 2; ++n) {
|
||||
std::string abuffer;
|
||||
abuffer.reserve(1000);
|
||||
abuffer.append(n, '\0');
|
||||
|
||||
SECTION("zero") {
|
||||
abuffer.append(load_data("fixed64/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed64() == 0ULL);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
abuffer.append(load_data("fixed64/data-pos"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed64() == 1ULL);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
abuffer.append(load_data("fixed64/data-max"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_fixed64() == std::numeric_limits<uint64_t>::max());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("end_of_buffer") {
|
||||
abuffer.append(load_data("fixed64/data-pos"));
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestBoolean;
|
||||
|
||||
message Test {
|
||||
|
||||
// this should be bool, but we are using uint32
|
||||
// to be able to encode values other than 0 (false)
|
||||
// and 1 (true)
|
||||
required uint32 b = 1;
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
|
BIN
third_party/protozero/test/t/bool/data-false.pbf
vendored
BIN
third_party/protozero/test/t/bool/data-false.pbf
vendored
Binary file not shown.
@ -1 +0,0 @@
|
||||
<08>
|
@ -1 +0,0 @@
|
||||
|
@ -1,141 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
namespace TestBoolean {
|
||||
|
||||
enum class Test : protozero::pbf_tag_type {
|
||||
required_bool_b = 1
|
||||
};
|
||||
|
||||
} // end namespace TestBoolean
|
||||
|
||||
TEST_CASE("read bool field using pbf_reader: false") {
|
||||
const std::string buffer = load_data("bool/data-false");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_FALSE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_reader: true") {
|
||||
const std::string buffer = load_data("bool/data-true");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_reader: also true") {
|
||||
const std::string buffer = load_data("bool/data-also-true");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next(1));
|
||||
REQUIRE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_reader: still true") {
|
||||
const std::string buffer = load_data("bool/data-still-true");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next(1));
|
||||
REQUIRE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_message: false") {
|
||||
const std::string buffer = load_data("bool/data-false");
|
||||
|
||||
protozero::pbf_message<TestBoolean::Test> item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE_FALSE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_message: true") {
|
||||
const std::string buffer = load_data("bool/data-true");
|
||||
|
||||
protozero::pbf_message<TestBoolean::Test> item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_message: also true") {
|
||||
const std::string buffer = load_data("bool/data-also-true");
|
||||
|
||||
protozero::pbf_message<TestBoolean::Test> item{buffer};
|
||||
|
||||
REQUIRE(item.next(TestBoolean::Test::required_bool_b));
|
||||
REQUIRE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bool field using pbf_message: still true") {
|
||||
const std::string buffer = load_data("bool/data-still-true");
|
||||
|
||||
protozero::pbf_message<TestBoolean::Test> item{buffer};
|
||||
|
||||
REQUIRE(item.next(TestBoolean::Test::required_bool_b));
|
||||
REQUIRE(item.get_bool());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("write bool field using pbf_writer") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("false") {
|
||||
pw.add_bool(1, false);
|
||||
REQUIRE(buffer == load_data("bool/data-false"));
|
||||
}
|
||||
|
||||
SECTION("true") {
|
||||
pw.add_bool(1, true);
|
||||
REQUIRE(buffer == load_data("bool/data-true"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write bool field using pbf_builder") {
|
||||
std::string buffer;
|
||||
protozero::pbf_builder<TestBoolean::Test> pw{buffer};
|
||||
|
||||
SECTION("false") {
|
||||
pw.add_bool(TestBoolean::Test::required_bool_b, false);
|
||||
REQUIRE(buffer == load_data("bool/data-false"));
|
||||
}
|
||||
|
||||
SECTION("true") {
|
||||
pw.add_bool(TestBoolean::Test::required_bool_b, true);
|
||||
REQUIRE(buffer == load_data("bool/data-true"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write bool field using moved pbf_builder") {
|
||||
std::string buffer;
|
||||
protozero::pbf_builder<TestBoolean::Test> pw2{buffer};
|
||||
REQUIRE(pw2.valid());
|
||||
|
||||
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, clang-analyzer-cplusplus.Move)
|
||||
|
||||
SECTION("false") {
|
||||
pw.add_bool(TestBoolean::Test::required_bool_b, false);
|
||||
REQUIRE(buffer == load_data("bool/data-false"));
|
||||
}
|
||||
|
||||
SECTION("true") {
|
||||
pw.add_bool(TestBoolean::Test::required_bool_b, true);
|
||||
REQUIRE(buffer == load_data("bool/data-true"));
|
||||
}
|
||||
}
|
||||
|
21
third_party/protozero/test/t/bool/testcase.cpp
vendored
21
third_party/protozero/test/t/bool/testcase.cpp
vendored
@ -1,21 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestBoolean::Test msg;
|
||||
|
||||
msg.set_b(0);
|
||||
write_to_file(msg, "data-false.pbf");
|
||||
|
||||
msg.set_b(1);
|
||||
write_to_file(msg, "data-true.pbf");
|
||||
|
||||
msg.set_b(2);
|
||||
write_to_file(msg, "data-also-true.pbf");
|
||||
|
||||
msg.set_b(2000);
|
||||
write_to_file(msg, "data-still-true.pbf");
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/bool/bool_testcase.pb.h"
|
||||
|
||||
TEMPLATE_TEST_CASE("write bool field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestBoolean::Test msg;
|
||||
|
||||
SECTION("false") {
|
||||
pw.add_bool(1, false);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE_FALSE(msg.b());
|
||||
}
|
||||
|
||||
SECTION("true") {
|
||||
pw.add_bool(1, true);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.b());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestBytes;
|
||||
|
||||
message Test {
|
||||
|
||||
required bytes s = 1;
|
||||
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
|
||||
|
BIN
third_party/protozero/test/t/bytes/data-empty.pbf
vendored
BIN
third_party/protozero/test/t/bytes/data-empty.pbf
vendored
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
|
||||
x
|
@ -1,2 +0,0 @@
|
||||
|
||||
foobar
|
@ -1,139 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
TEST_CASE("read bytes field: empty") {
|
||||
const std::string buffer = load_data("bytes/data-empty");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_bytes().empty());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bytes field: one") {
|
||||
const std::string buffer = load_data("bytes/data-one");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_bytes() == "x");
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bytes field: string") {
|
||||
const std::string buffer = load_data("bytes/data-string");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_bytes() == "foobar");
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bytes field: binary") {
|
||||
const std::string buffer = load_data("bytes/data-binary");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
const std::string data = item.get_bytes();
|
||||
REQUIRE(data.size() == 3);
|
||||
REQUIRE(data[0] == char(1));
|
||||
REQUIRE(data[1] == char(2));
|
||||
REQUIRE(data[2] == char(3));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read bytes field: end of buffer") {
|
||||
const std::string buffer = load_data("bytes/data-binary");
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write bytes field") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("empty") {
|
||||
pw.add_string(1, "");
|
||||
REQUIRE(buffer == load_data("bytes/data-empty"));
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
pw.add_string(1, "x");
|
||||
REQUIRE(buffer == load_data("bytes/data-one"));
|
||||
}
|
||||
|
||||
SECTION("string") {
|
||||
pw.add_string(1, "foobar");
|
||||
REQUIRE(buffer == load_data("bytes/data-string"));
|
||||
}
|
||||
|
||||
SECTION("binary") {
|
||||
std::string data;
|
||||
data.append(1, char(1));
|
||||
data.append(1, char(2));
|
||||
data.append(1, char(3));
|
||||
|
||||
pw.add_string(1, data);
|
||||
|
||||
REQUIRE(buffer == load_data("bytes/data-binary"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write bytes field using vectored approach") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("using two strings") {
|
||||
std::string d1{"foo"};
|
||||
std::string d2{"bar"};
|
||||
|
||||
pw.add_bytes_vectored(1, d1, d2);
|
||||
}
|
||||
|
||||
SECTION("using a string and a dataview") {
|
||||
std::string d1{"foo"};
|
||||
std::string d2{"bar"};
|
||||
protozero::data_view dv{d2};
|
||||
|
||||
pw.add_bytes_vectored(1, d1, dv);
|
||||
}
|
||||
|
||||
SECTION("using three strings") {
|
||||
std::string d1{"foo"};
|
||||
std::string d2{"ba"};
|
||||
std::string d3{"r"};
|
||||
|
||||
pw.add_bytes_vectored(1, d1, d2, d3);
|
||||
}
|
||||
|
||||
SECTION("with empty string") {
|
||||
std::string d1{"foo"};
|
||||
std::string d2{};
|
||||
std::string d3{"bar"};
|
||||
|
||||
pw.add_bytes_vectored(1, d1, d2, d3);
|
||||
}
|
||||
|
||||
REQUIRE(buffer == load_data("bytes/data-string"));
|
||||
}
|
||||
|
||||
TEST_CASE("write bytes field using vectored approach with builder") {
|
||||
enum class foo : protozero::pbf_tag_type { bar = 1 };
|
||||
std::string buffer;
|
||||
protozero::pbf_builder<foo> pw{buffer};
|
||||
|
||||
const std::string d1{"foo"};
|
||||
const std::string d2{"bar"};
|
||||
|
||||
pw.add_bytes_vectored(foo::bar, d1, d2);
|
||||
|
||||
REQUIRE(buffer == load_data("bytes/data-string"));
|
||||
}
|
||||
|
25
third_party/protozero/test/t/bytes/testcase.cpp
vendored
25
third_party/protozero/test/t/bytes/testcase.cpp
vendored
@ -1,25 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestBytes::Test msg;
|
||||
|
||||
msg.set_s("");
|
||||
write_to_file(msg, "data-empty.pbf");
|
||||
|
||||
msg.set_s("x");
|
||||
write_to_file(msg, "data-one.pbf");
|
||||
|
||||
msg.set_s("foobar");
|
||||
write_to_file(msg, "data-string.pbf");
|
||||
|
||||
std::string data;
|
||||
data.append(1, char(1));
|
||||
data.append(1, char(2));
|
||||
data.append(1, char(3));
|
||||
msg.set_s(data);
|
||||
write_to_file(msg, "data-binary.pbf");
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/bytes/bytes_testcase.pb.h"
|
||||
|
||||
TEMPLATE_TEST_CASE("write bytes field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestBytes::Test msg;
|
||||
|
||||
SECTION("empty") {
|
||||
pw.add_string(1, "");
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s().empty());
|
||||
}
|
||||
|
||||
SECTION("one") {
|
||||
pw.add_string(1, "x");
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s() == "x");
|
||||
}
|
||||
|
||||
SECTION("string") {
|
||||
pw.add_string(1, "foobar");
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s() == "foobar");
|
||||
}
|
||||
|
||||
SECTION("binary") {
|
||||
std::string data;
|
||||
data.append(1, char(1));
|
||||
data.append(1, char(2));
|
||||
data.append(1, char(3));
|
||||
|
||||
pw.add_string(1, data);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.s().size() == 3);
|
||||
REQUIRE(msg.s()[1] == char(2));
|
||||
REQUIRE(msg.s()[2] == char(3));
|
||||
REQUIRE(msg.s()[2] == char(3));
|
||||
}
|
||||
|
||||
}
|
||||
|
BIN
third_party/protozero/test/t/complex/data-all.pbf
vendored
BIN
third_party/protozero/test/t/complex/data-all.pbf
vendored
Binary file not shown.
Binary file not shown.
BIN
third_party/protozero/test/t/complex/data-some.pbf
vendored
BIN
third_party/protozero/test/t/complex/data-some.pbf
vendored
Binary file not shown.
@ -1,742 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#include <protozero/buffer_fixed.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
|
||||
namespace TestComplex {
|
||||
|
||||
enum class Test : protozero::pbf_tag_type {
|
||||
required_fixed32_f = 1,
|
||||
optional_int64_i = 2,
|
||||
optional_int64_j = 3,
|
||||
required_Sub_submessage = 5,
|
||||
optional_string_s = 8,
|
||||
repeated_uint32_u = 4,
|
||||
packed_sint32_d = 7
|
||||
};
|
||||
|
||||
enum class Sub : protozero::pbf_tag_type {
|
||||
required_string_s = 1
|
||||
};
|
||||
|
||||
} // namespace TestComplex
|
||||
|
||||
TEST_CASE("read complex data using pbf_reader: minimal") {
|
||||
const std::string buffer = load_data("complex/data-minimal");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case 1: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_reader: some") {
|
||||
const std::string buffer = load_data("complex/data-some");
|
||||
|
||||
protozero::pbf_reader item2{buffer};
|
||||
protozero::pbf_reader item;
|
||||
using std::swap;
|
||||
swap(item, item2);
|
||||
|
||||
uint32_t sum_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 4: {
|
||||
sum_of_u += item.get_uint32();
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(sum_of_u == 66);
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_reader: all") {
|
||||
const std::string buffer = load_data("complex/data-all");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_reader: skip everything") {
|
||||
const std::string buffer = load_data("complex/data-all");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
item.skip();
|
||||
break;
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_message: minimal") {
|
||||
const std::string buffer = load_data("complex/data-minimal");
|
||||
|
||||
protozero::pbf_message<TestComplex::Test> item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case TestComplex::Test::required_fixed32_f: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::required_Sub_submessage: {
|
||||
protozero::pbf_message<TestComplex::Sub> subitem{item.get_message()};
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_message: some") {
|
||||
const std::string buffer = load_data("complex/data-some");
|
||||
|
||||
protozero::pbf_message<TestComplex::Test> item2{buffer};
|
||||
protozero::pbf_message<TestComplex::Test> item;
|
||||
using std::swap;
|
||||
swap(item, item2);
|
||||
|
||||
uint32_t sum_of_u = 0;
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case TestComplex::Test::required_fixed32_f: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::optional_int64_i: {
|
||||
REQUIRE(true);
|
||||
item.skip();
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::repeated_uint32_u: {
|
||||
sum_of_u += item.get_uint32();
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::required_Sub_submessage: {
|
||||
protozero::pbf_message<TestComplex::Sub> subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(sum_of_u == 66);
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_message: all") {
|
||||
const std::string buffer = load_data("complex/data-all");
|
||||
|
||||
protozero::pbf_message<TestComplex::Test> item{buffer};
|
||||
|
||||
int number_of_u = 0;
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case TestComplex::Test::required_fixed32_f: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::optional_int64_i: {
|
||||
REQUIRE(true);
|
||||
item.skip();
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::optional_int64_j: {
|
||||
REQUIRE(item.get_int64() == 555555555LL);
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::repeated_uint32_u: {
|
||||
item.skip();
|
||||
++number_of_u;
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::required_Sub_submessage: {
|
||||
protozero::pbf_message<TestComplex::Sub> subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::packed_sint32_d: {
|
||||
const auto pi = item.get_packed_sint32();
|
||||
REQUIRE(std::accumulate(pi.cbegin(), pi.cend(), 0) == 5);
|
||||
break;
|
||||
}
|
||||
case TestComplex::Test::optional_string_s: {
|
||||
REQUIRE(item.get_string() == "optionalstring");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(number_of_u == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("read complex data using pbf_message: skip everything") {
|
||||
const std::string buffer = load_data("complex/data-all");
|
||||
|
||||
protozero::pbf_message<TestComplex::Test> item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case TestComplex::Test::required_fixed32_f:
|
||||
case TestComplex::Test::optional_int64_i:
|
||||
case TestComplex::Test::optional_int64_j:
|
||||
case TestComplex::Test::repeated_uint32_u:
|
||||
case TestComplex::Test::required_Sub_submessage:
|
||||
case TestComplex::Test::packed_sint32_d:
|
||||
case TestComplex::Test::optional_string_s:
|
||||
item.skip();
|
||||
break;
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using pbf_writer: minimal") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
pw.add_fixed32(1, 12345678);
|
||||
|
||||
std::string submessage;
|
||||
protozero::pbf_writer pws{submessage};
|
||||
pws.add_string(1, "foobar");
|
||||
|
||||
pw.add_message(5, submessage);
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case 1: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using pbf_writer: some") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw2{buffer};
|
||||
pw2.add_fixed32(1, 12345678);
|
||||
|
||||
protozero::pbf_writer pw;
|
||||
using std::swap;
|
||||
swap(pw, pw2);
|
||||
|
||||
REQUIRE(pw.valid());
|
||||
REQUIRE_FALSE(pw2.valid());
|
||||
|
||||
std::string submessage;
|
||||
protozero::pbf_writer pws{submessage};
|
||||
pws.add_string(1, "foobar");
|
||||
|
||||
pw.add_uint32(4, 22);
|
||||
pw.add_uint32(4, 44);
|
||||
pw.add_int64(2, -9876543);
|
||||
pw.add_message(5, submessage);
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
uint32_t sum_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 4: {
|
||||
sum_of_u += item.get_uint32();
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
const auto view = item.get_view();
|
||||
protozero::pbf_reader subitem{view};
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(std::string(subitem.get_view()) == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(sum_of_u == 66);
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using pbf_writer: all") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
pw.add_fixed32(1, 12345678);
|
||||
|
||||
std::string submessage;
|
||||
protozero::pbf_writer pws{submessage};
|
||||
pws.add_string(1, "foobar");
|
||||
pw.add_message(5, submessage);
|
||||
|
||||
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};
|
||||
|
||||
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;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(number_of_u == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using pbf_builder: minimal") {
|
||||
std::string buffer;
|
||||
protozero::pbf_builder<TestComplex::Test> pw{buffer};
|
||||
pw.add_fixed32(TestComplex::Test::required_fixed32_f, 12345678);
|
||||
|
||||
std::string submessage;
|
||||
protozero::pbf_builder<TestComplex::Sub> pws{submessage};
|
||||
pws.add_string(TestComplex::Sub::required_string_s, "foobar");
|
||||
|
||||
pw.add_message(TestComplex::Test::required_Sub_submessage, submessage);
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case 1: {
|
||||
REQUIRE(item.get_fixed32() == 12345678L);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using pbf_builder: some") {
|
||||
std::string buffer;
|
||||
protozero::pbf_builder<TestComplex::Test> pw2{buffer};
|
||||
pw2.add_fixed32(TestComplex::Test::required_fixed32_f, 12345678);
|
||||
|
||||
std::string dummy_buffer;
|
||||
protozero::pbf_builder<TestComplex::Test> pw{dummy_buffer};
|
||||
using std::swap;
|
||||
swap(pw, pw2);
|
||||
|
||||
std::string submessage;
|
||||
protozero::pbf_builder<TestComplex::Sub> pws{submessage};
|
||||
pws.add_string(TestComplex::Sub::required_string_s, "foobar");
|
||||
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 22);
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 44);
|
||||
pw.add_int64(TestComplex::Test::optional_int64_i, -9876543);
|
||||
pw.add_message(TestComplex::Test::required_Sub_submessage, submessage);
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
uint32_t sum_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 4: {
|
||||
sum_of_u += item.get_uint32();
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(sum_of_u == 66);
|
||||
}
|
||||
|
||||
TEST_CASE("write complex data using pbf_builder: all") {
|
||||
std::string buffer;
|
||||
protozero::pbf_builder<TestComplex::Test> pw{buffer};
|
||||
pw.add_fixed32(TestComplex::Test::required_fixed32_f, 12345678);
|
||||
|
||||
std::string submessage;
|
||||
protozero::pbf_builder<TestComplex::Sub> pws{submessage};
|
||||
pws.add_string(TestComplex::Sub::required_string_s, "foobar");
|
||||
pw.add_message(TestComplex::Test::required_Sub_submessage, submessage);
|
||||
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 22);
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 44);
|
||||
pw.add_int64(TestComplex::Test::optional_int64_i, -9876543);
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 44);
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 66);
|
||||
pw.add_uint32(TestComplex::Test::repeated_uint32_u, 66);
|
||||
|
||||
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);
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
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;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(number_of_u == 5);
|
||||
}
|
||||
|
||||
static void check_message(const std::string& buffer) {
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
while (item.next()) {
|
||||
switch (item.tag()) {
|
||||
case 1: {
|
||||
REQUIRE(item.get_fixed32() == 42L);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
protozero::pbf_reader subitem = item.get_message();
|
||||
REQUIRE(subitem.next());
|
||||
REQUIRE(subitem.get_string() == "foobar");
|
||||
REQUIRE_FALSE(subitem.next());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
REQUIRE(false); // should not be here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write complex with subwriter using pbf_writer") {
|
||||
std::string buffer_test;
|
||||
protozero::pbf_writer pbf_test{buffer_test};
|
||||
pbf_test.add_fixed32(1, 42L);
|
||||
|
||||
SECTION("message in message") {
|
||||
protozero::pbf_writer pbf_submessage{pbf_test, 5};
|
||||
pbf_submessage.add_string(1, "foobar");
|
||||
}
|
||||
|
||||
check_message(buffer_test);
|
||||
}
|
||||
|
||||
TEST_CASE("write complex with subwriter using pbf_builder") {
|
||||
std::string buffer_test;
|
||||
protozero::pbf_builder<TestComplex::Test> pbf_test{buffer_test};
|
||||
pbf_test.add_fixed32(TestComplex::Test::required_fixed32_f, 42L);
|
||||
|
||||
SECTION("message in message") {
|
||||
protozero::pbf_builder<TestComplex::Sub> pbf_submessage{pbf_test, TestComplex::Test::required_Sub_submessage};
|
||||
pbf_submessage.add_string(TestComplex::Sub::required_string_s, "foobar");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestComplex::Test msg;
|
||||
|
||||
msg.set_f(12345678);
|
||||
TestComplex::Sub* submsg = msg.mutable_submessage();
|
||||
submsg->set_s("foobar");
|
||||
|
||||
write_to_file(msg, "data-minimal.pbf");
|
||||
|
||||
msg.add_u(22);
|
||||
msg.add_u(44);
|
||||
msg.set_i(-9876543);
|
||||
|
||||
write_to_file(msg, "data-some.pbf");
|
||||
|
||||
msg.set_s("optionalstring");
|
||||
msg.add_u(44);
|
||||
msg.add_u(66);
|
||||
msg.add_u(66);
|
||||
msg.add_d(-17);
|
||||
msg.add_d(22);
|
||||
msg.set_j(555555555);
|
||||
|
||||
write_to_file(msg, "data-all.pbf");
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestComplex;
|
||||
|
||||
message Sub {
|
||||
required string s = 1;
|
||||
}
|
||||
|
||||
message Test {
|
||||
required fixed32 f = 1;
|
||||
optional int64 i = 2;
|
||||
optional int64 j = 3;
|
||||
required Sub submessage = 5;
|
||||
optional string s = 8;
|
||||
repeated uint32 u = 4;
|
||||
repeated sint32 d = 7 [packed=true];
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
ラ」p=*ツタ
|
@ -1 +0,0 @@
|
||||
<09>O<EFBFBD><4F>n<EFBFBD>@
|
BIN
third_party/protozero/test/t/double/data-zero.pbf
vendored
BIN
third_party/protozero/test/t/double/data-zero.pbf
vendored
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestDouble;
|
||||
|
||||
message Test {
|
||||
|
||||
required double x = 1;
|
||||
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
TEST_CASE("read 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
|
||||
// is aligned before that, in at least one of these cases the double will
|
||||
// not be aligned properly. So we test that even in that case the double
|
||||
// will be extracted properly.
|
||||
for (std::string::size_type n = 0; n < 2; ++n) {
|
||||
std::string abuffer;
|
||||
abuffer.reserve(1000);
|
||||
abuffer.append(n, '\0');
|
||||
|
||||
SECTION("zero") {
|
||||
abuffer.append(load_data("double/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_double() == Approx(0.0));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
abuffer.append(load_data("double/data-pos"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_double() == Approx(4.893));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
abuffer.append(load_data("double/data-neg"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_double() == Approx(-9232.33));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("end_of_buffer") {
|
||||
abuffer.append(load_data("double/data-neg"));
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write double field") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_double(1, 0.0);
|
||||
REQUIRE(buffer == load_data("double/data-zero"));
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_double(1, 4.893);
|
||||
REQUIRE(buffer == load_data("double/data-pos"));
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_double(1, -9232.33);
|
||||
REQUIRE(buffer == load_data("double/data-neg"));
|
||||
}
|
||||
}
|
||||
|
18
third_party/protozero/test/t/double/testcase.cpp
vendored
18
third_party/protozero/test/t/double/testcase.cpp
vendored
@ -1,18 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestDouble::Test msg;
|
||||
|
||||
msg.set_x(0.0);
|
||||
write_to_file(msg, "data-zero.pbf");
|
||||
|
||||
msg.set_x(4.893);
|
||||
write_to_file(msg, "data-pos.pbf");
|
||||
|
||||
msg.set_x(-9232.33);
|
||||
write_to_file(msg, "data-neg.pbf");
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/double/double_testcase.pb.h"
|
||||
|
||||
TEMPLATE_TEST_CASE("write double field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestDouble::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_double(1, 0.0);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.x() == Approx(0.0));
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_double(1, 4.893);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.x() == Approx(4.893));
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_double(1, -9232.33);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.x() == Approx(-9232.33));
|
||||
}
|
||||
|
||||
}
|
||||
|
BIN
third_party/protozero/test/t/enum/data-black.pbf
vendored
BIN
third_party/protozero/test/t/enum/data-black.pbf
vendored
Binary file not shown.
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1,26 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestEnum;
|
||||
|
||||
enum Color {
|
||||
BLACK = 0;
|
||||
RED = 1;
|
||||
GREEN = 2;
|
||||
BLUE = 3;
|
||||
MAX = 2147483646;
|
||||
NEG = -1;
|
||||
|
||||
// Older versions (before 2.6.0) of the google protobuf compiler have a
|
||||
// bug and don't allow the real minimum of -2147483648, so we are testing
|
||||
// with this.
|
||||
MIN = -2147483647;
|
||||
}
|
||||
|
||||
message Test {
|
||||
|
||||
required Color color = 1;
|
||||
|
||||
}
|
||||
|
@ -1,83 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
TEST_CASE("read enum field: zero") {
|
||||
const std::string buffer = load_data("enum/data-black");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_enum() == 0L);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read enum field: positive") {
|
||||
const std::string buffer = load_data("enum/data-blue");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_enum() == 3L);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read enum field: negative") {
|
||||
const std::string buffer = load_data("enum/data-neg");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_enum() == -1L);
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read enum field: max") {
|
||||
const std::string buffer = load_data("enum/data-max");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_enum() == std::numeric_limits<int32_t>::max());
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("read enum field: min") {
|
||||
const std::string buffer = load_data("enum/data-min");
|
||||
|
||||
protozero::pbf_reader item{buffer};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(item.get_enum() == (std::numeric_limits<int32_t>::min() + 1));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
TEST_CASE("write enum field") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_enum(1, 0L);
|
||||
REQUIRE(buffer == load_data("enum/data-black"));
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_enum(1, 3L);
|
||||
REQUIRE(buffer == load_data("enum/data-blue"));
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_enum(1, -1L);
|
||||
REQUIRE(buffer == load_data("enum/data-neg"));
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
pw.add_enum(1, std::numeric_limits<int32_t>::max());
|
||||
REQUIRE(buffer == load_data("enum/data-max"));
|
||||
}
|
||||
|
||||
SECTION("min") {
|
||||
pw.add_enum(1, std::numeric_limits<int32_t>::min() + 1);
|
||||
REQUIRE(buffer == load_data("enum/data-min"));
|
||||
}
|
||||
}
|
||||
|
24
third_party/protozero/test/t/enum/testcase.cpp
vendored
24
third_party/protozero/test/t/enum/testcase.cpp
vendored
@ -1,24 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestEnum::Test msg;
|
||||
|
||||
msg.set_color(TestEnum::BLACK);
|
||||
write_to_file(msg, "data-black.pbf");
|
||||
|
||||
msg.set_color(TestEnum::BLUE);
|
||||
write_to_file(msg, "data-blue.pbf");
|
||||
|
||||
msg.set_color(TestEnum::NEG);
|
||||
write_to_file(msg, "data-neg.pbf");
|
||||
|
||||
msg.set_color(TestEnum::MAX);
|
||||
write_to_file(msg, "data-max.pbf");
|
||||
|
||||
msg.set_color(TestEnum::MIN);
|
||||
write_to_file(msg, "data-min.pbf");
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/enum/enum_testcase.pb.h"
|
||||
|
||||
TEMPLATE_TEST_CASE("write enum field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestEnum::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_enum(1, 0L);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::BLACK);
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_enum(1, 3L);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::BLUE);
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_enum(1, -1L);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::NEG);
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
pw.add_enum(1, std::numeric_limits<int32_t>::max() - 1);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::MAX);
|
||||
}
|
||||
|
||||
SECTION("min") {
|
||||
pw.add_enum(1, std::numeric_limits<int32_t>::min() + 1);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.color() == TestEnum::Color::MIN);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<0A><><EFBFBD><EFBFBD>
|
BIN
third_party/protozero/test/t/fixed32/data-pos.pbf
vendored
BIN
third_party/protozero/test/t/fixed32/data-pos.pbf
vendored
Binary file not shown.
BIN
third_party/protozero/test/t/fixed32/data-pos200.pbf
vendored
BIN
third_party/protozero/test/t/fixed32/data-pos200.pbf
vendored
Binary file not shown.
BIN
third_party/protozero/test/t/fixed32/data-zero.pbf
vendored
BIN
third_party/protozero/test/t/fixed32/data-zero.pbf
vendored
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestFixed32;
|
||||
|
||||
message Test {
|
||||
|
||||
required fixed32 i = 1;
|
||||
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#define PBF_TYPE fixed32
|
||||
#define PBF_TYPE_IS_SIGNED 0
|
||||
using cpp_type = uint32_t;
|
||||
|
||||
#include <scalar_access.hpp>
|
||||
|
@ -1,21 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestFixed32::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
write_to_file(msg, "data-zero.pbf");
|
||||
|
||||
msg.set_i(1);
|
||||
write_to_file(msg, "data-pos.pbf");
|
||||
|
||||
msg.set_i(200);
|
||||
write_to_file(msg, "data-pos200.pbf");
|
||||
|
||||
msg.set_i(std::numeric_limits<uint32_t>::max());
|
||||
write_to_file(msg, "data-max.pbf");
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/fixed32/fixed32_testcase.pb.h"
|
||||
|
||||
TEMPLATE_TEST_CASE("write fixed32 field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestFixed32::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_fixed32(1, 0);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 0);
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
pw.add_fixed32(1, std::numeric_limits<uint32_t>::max());
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<uint32_t>::max());
|
||||
}
|
||||
|
||||
SECTION("min") {
|
||||
pw.add_fixed32(1, std::numeric_limits<uint32_t>::min());
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<uint32_t>::min());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
BIN
third_party/protozero/test/t/fixed64/data-pos.pbf
vendored
BIN
third_party/protozero/test/t/fixed64/data-pos.pbf
vendored
Binary file not shown.
BIN
third_party/protozero/test/t/fixed64/data-pos200.pbf
vendored
BIN
third_party/protozero/test/t/fixed64/data-pos200.pbf
vendored
Binary file not shown.
BIN
third_party/protozero/test/t/fixed64/data-zero.pbf
vendored
BIN
third_party/protozero/test/t/fixed64/data-zero.pbf
vendored
Binary file not shown.
@ -1,9 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#define PBF_TYPE fixed64
|
||||
#define PBF_TYPE_IS_SIGNED 0
|
||||
using cpp_type = uint64_t;
|
||||
|
||||
#include <scalar_access.hpp>
|
||||
|
@ -1,21 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestFixed64::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
write_to_file(msg, "data-zero.pbf");
|
||||
|
||||
msg.set_i(1);
|
||||
write_to_file(msg, "data-pos.pbf");
|
||||
|
||||
msg.set_i(200);
|
||||
write_to_file(msg, "data-pos200.pbf");
|
||||
|
||||
msg.set_i(std::numeric_limits<uint64_t>::max());
|
||||
write_to_file(msg, "data-max.pbf");
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestFixed64;
|
||||
|
||||
message Test {
|
||||
|
||||
required fixed64 i = 1;
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
H瞽ソ
|
@ -1 +0,0 @@
|
||||
H皙@
|
BIN
third_party/protozero/test/t/float/data-zero.pbf
vendored
BIN
third_party/protozero/test/t/float/data-zero.pbf
vendored
Binary file not shown.
@ -1,74 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
TEST_CASE("read 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
|
||||
// is aligned before that, in at least one of these cases the float will
|
||||
// not be aligned properly. So we test that even in that case the float
|
||||
// will be extracted properly.
|
||||
|
||||
for (std::string::size_type n = 0; n < 2; ++n) {
|
||||
std::string abuffer;
|
||||
abuffer.reserve(1000);
|
||||
abuffer.append(n, '\0');
|
||||
|
||||
SECTION("zero") {
|
||||
abuffer.append(load_data("float/data-zero"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(double(item.get_float()) == Approx(0.0));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
abuffer.append(load_data("float/data-pos"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(double(item.get_float()) == Approx(5.34));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
abuffer.append(load_data("float/data-neg"));
|
||||
protozero::pbf_reader item{abuffer.data() + n, abuffer.size() - n};
|
||||
|
||||
REQUIRE(item.next());
|
||||
REQUIRE(double(item.get_float()) == Approx(-1.71));
|
||||
REQUIRE_FALSE(item.next());
|
||||
}
|
||||
|
||||
SECTION("end_of_buffer") {
|
||||
abuffer.append(load_data("float/data-neg"));
|
||||
|
||||
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(), protozero::end_of_buffer_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write float field") {
|
||||
std::string buffer;
|
||||
protozero::pbf_writer pw{buffer};
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_float(1, 0.0F);
|
||||
REQUIRE(buffer == load_data("float/data-zero"));
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_float(1, 5.34F);
|
||||
REQUIRE(buffer == load_data("float/data-pos"));
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_float(1, -1.71F);
|
||||
REQUIRE(buffer == load_data("float/data-neg"));
|
||||
}
|
||||
}
|
||||
|
18
third_party/protozero/test/t/float/testcase.cpp
vendored
18
third_party/protozero/test/t/float/testcase.cpp
vendored
@ -1,18 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestFloat::Test msg;
|
||||
|
||||
msg.set_x(0.0);
|
||||
write_to_file(msg, "data-zero.pbf");
|
||||
|
||||
msg.set_x(5.34);
|
||||
write_to_file(msg, "data-pos.pbf");
|
||||
|
||||
msg.set_x(-1.71);
|
||||
write_to_file(msg, "data-neg.pbf");
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestFloat;
|
||||
|
||||
message Test {
|
||||
|
||||
required float x = 1;
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
羹<><E7BEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
И
|
BIN
third_party/protozero/test/t/int32/data-zero.pbf
vendored
BIN
third_party/protozero/test/t/int32/data-zero.pbf
vendored
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
syntax = "proto2";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
package TestInt32;
|
||||
|
||||
message Test {
|
||||
|
||||
required int32 i = 1;
|
||||
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
|
||||
#include <test.hpp>
|
||||
|
||||
#define PBF_TYPE int32
|
||||
#define PBF_TYPE_IS_SIGNED 1
|
||||
using cpp_type = int32_t;
|
||||
|
||||
#include <scalar_access.hpp>
|
||||
|
30
third_party/protozero/test/t/int32/testcase.cpp
vendored
30
third_party/protozero/test/t/int32/testcase.cpp
vendored
@ -1,30 +0,0 @@
|
||||
|
||||
#include <testcase.hpp>
|
||||
|
||||
#include "testcase.pb.h"
|
||||
|
||||
int main() {
|
||||
TestInt32::Test msg;
|
||||
|
||||
msg.set_i(0);
|
||||
write_to_file(msg, "data-zero.pbf");
|
||||
|
||||
msg.set_i(1);
|
||||
write_to_file(msg, "data-pos.pbf");
|
||||
|
||||
msg.set_i(200);
|
||||
write_to_file(msg, "data-pos200.pbf");
|
||||
|
||||
msg.set_i(-1);
|
||||
write_to_file(msg, "data-neg.pbf");
|
||||
|
||||
msg.set_i(-200);
|
||||
write_to_file(msg, "data-neg200.pbf");
|
||||
|
||||
msg.set_i(std::numeric_limits<int32_t>::max());
|
||||
write_to_file(msg, "data-max.pbf");
|
||||
|
||||
msg.set_i(std::numeric_limits<int32_t>::min());
|
||||
write_to_file(msg, "data-min.pbf");
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
|
||||
#include <buffer.hpp>
|
||||
|
||||
#include "t/int32/int32_testcase.pb.h"
|
||||
|
||||
TEMPLATE_TEST_CASE("write int32 field and check with libprotobuf", "",
|
||||
buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {
|
||||
|
||||
TestType buffer;
|
||||
typename TestType::writer_type pw{buffer.buffer()};
|
||||
|
||||
TestInt32::Test msg;
|
||||
|
||||
SECTION("zero") {
|
||||
pw.add_int32(1, 0L);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 0L);
|
||||
}
|
||||
|
||||
SECTION("positive") {
|
||||
pw.add_int32(1, 1L);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == 1L);
|
||||
}
|
||||
|
||||
SECTION("negative") {
|
||||
pw.add_int32(1, -1L);
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == -1L);
|
||||
}
|
||||
|
||||
SECTION("max") {
|
||||
pw.add_int32(1, std::numeric_limits<int32_t>::max());
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<int32_t>::max());
|
||||
}
|
||||
|
||||
SECTION("min") {
|
||||
pw.add_int32(1, std::numeric_limits<int32_t>::min());
|
||||
|
||||
msg.ParseFromArray(buffer.data(), buffer.size());
|
||||
|
||||
REQUIRE(msg.i() == std::numeric_limits<int32_t>::min());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
€€€€€€€€€
|
@ -1 +0,0 @@
|
||||
<08><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
羹<><E7BEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
И
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user