[protozero] 01/04: Imported Upstream version 1.2.3
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Tue Dec 1 08:29:16 UTC 2015
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository protozero.
commit 515c9d9d3b0336edadc214357363a13d83846e38
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Tue Dec 1 09:10:30 2015 +0100
Imported Upstream version 1.2.3
---
.gitattributes | 1 +
.gitignore | 1 +
CHANGELOG.md | 18 +++-
Makefile | 2 +-
README.md | 22 +++++
appveyor.yml | 12 +--
build-appveyor.bat | 79 +++++++++++++++++
build-local.bat | 29 +++++++
common.gypi | 52 ++----------
include/protozero/byteswap.hpp | 10 ++-
include/protozero/config.hpp | 57 +++++++++++++
include/protozero/pbf_reader.hpp | 34 ++++----
include/protozero/pbf_writer.hpp | 13 +--
include/protozero/version.hpp | 4 +-
protozero.gyp | 59 +++++--------
test/include/testcase.hpp | 2 +-
test/t/basic/test_cases.cpp | 2 +-
test/t/bool/test_cases.cpp | 16 ++--
test/t/bytes/test_cases.cpp | 14 ++--
test/t/complex/test_cases.cpp | 16 ++--
test/t/double/test_cases.cpp | 65 ++++++++------
test/t/endian/test_cases.cpp | 8 +-
test/t/enum/test_cases.cpp | 4 +-
test/t/fixed32/test_cases.cpp | 112 +++++++++++++------------
test/t/fixed64/test_cases.cpp | 65 ++++++++------
test/t/float/test_cases.cpp | 65 ++++++++------
test/t/int32/test_cases.cpp | 18 ++--
test/t/int64/test_cases.cpp | 16 ++--
test/t/message/test_cases.cpp | 10 +--
test/t/nested/test_cases.cpp | 4 +-
test/t/repeated/test_cases.cpp | 10 +--
test/t/repeated_packed_bool/test_cases.cpp | 10 +--
test/t/repeated_packed_double/test_cases.cpp | 81 ++++++++++--------
test/t/repeated_packed_enum/test_cases.cpp | 10 +--
test/t/repeated_packed_fixed32/test_cases.cpp | 79 +++++++++--------
test/t/repeated_packed_fixed64/test_cases.cpp | 79 +++++++++--------
test/t/repeated_packed_float/test_cases.cpp | 81 ++++++++++--------
test/t/repeated_packed_int32/test_cases.cpp | 10 +--
test/t/repeated_packed_int64/test_cases.cpp | 10 +--
test/t/repeated_packed_sfixed32/test_cases.cpp | 10 +--
test/t/repeated_packed_sfixed64/test_cases.cpp | 10 +--
test/t/repeated_packed_sint32/test_cases.cpp | 10 +--
test/t/repeated_packed_sint64/test_cases.cpp | 10 +--
test/t/repeated_packed_uint32/test_cases.cpp | 10 +--
test/t/repeated_packed_uint64/test_cases.cpp | 10 +--
test/t/sfixed32/test_cases.cpp | 10 +--
test/t/sfixed64/test_cases.cpp | 10 +--
test/t/sint32/test_cases.cpp | 14 ++--
test/t/sint64/test_cases.cpp | 14 ++--
test/t/skip/test_cases.cpp | 4 +-
test/t/string/test_cases.cpp | 12 +--
test/t/uint32/test_cases.cpp | 10 +--
test/t/uint64/test_cases.cpp | 10 +--
test/t/vector_tile/test_cases.cpp | 8 +-
test/tests.cpp | 2 +-
tutorial.md | 4 +-
56 files changed, 786 insertions(+), 552 deletions(-)
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..3503e2c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+*.pbf -text
diff --git a/.gitignore b/.gitignore
index ccd5ce5..68e1aeb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ deps
*.sln
*.suo
*.vcxproj*
+*.7z
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07f64bd..60bc829 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,11 +8,26 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
+- Added `config.hpp` header which now includes all the macro magic to
+ configure the library for different architectures etc.
+
### Changed
### Fixed
+## [1.2.3] - 2015-11-30
+
+### Added
+
+- Added `config.hpp` header which now includes all the macro magic to
+ configure the library for different architectures etc.
+
+### Fixed
+
+- Unaligned access to floats/doubles on some ARM architectures.
+
+
## [1.2.2] - 2015-10-13
### Fixed
@@ -48,7 +63,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.2.2...HEAD
+[unreleased]: https://github.com/osmcode/libosmium/compare/v1.2.3...HEAD
+[1.2.3]: https://github.com/osmcode/libosmium/compare/v1.2.2...v1.2.3
[1.2.2]: https://github.com/osmcode/libosmium/compare/v1.2.1...v1.2.2
[1.2.1]: https://github.com/osmcode/libosmium/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/osmcode/libosmium/compare/v1.1.0...v1.2.0
diff --git a/Makefile b/Makefile
index 801897c..c760e0a 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ HPP_FILES := include/protozero/byteswap.hpp \
include/protozero/pbf_reader.hpp \
include/protozero/pbf_writer.hpp
-CFLAGS_PROTOBUF := $(shell pkg-config protobuf --cflags)
+CFLAGS_PROTOBUF := $(subst -I,-isystem ,$(shell pkg-config protobuf --cflags))
LDFLAGS_PROTOBUF := $(shell pkg-config protobuf --libs-only-L)
all: ./test/tests test/writer_tests
diff --git a/README.md b/README.md
index 695442a..09bde83 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,28 @@ Call `make doc` to build the Doxygen documentation. (You'll need
https://developers.google.com/protocol-buffers/docs/proto3#maps.
+## Memory Alignment Issues and Endianness
+
+Protobuf-encoded data is not necessarily properly aligned for the machine we
+are using. For single values this isn't a problem, because we copy those into
+a properly aligned variable and return that one. But for repeated packed values
+it can be a problem, because we give users access to them through an iterator.
+To get the best performance this iterator is usually just a raw pointer. This
+works fine on Intel processors, non-aligned access is just slower than aligned
+access. On ARM this is not necessarily the case (depends on machine type and
+compile options), so we need to go through a special iterator there
+which makes sure to return aligned data on member access. Basically the same
+iterator is used on big endian architectures to put the bytes in the correct
+order before handing them back to the application.
+
+Detection of endianess and those architectures which have problems with
+non-aligned data is not perfect. If tests fail for you, this might be a problem
+in your setup. Please open an issue on Github in this case and tell us about
+your system.
+
+See also the discussion on https://github.com/mapbox/protozero/issues/33 .
+
+
## Tests
Extensive tests are included. Call
diff --git a/appveyor.yml b/appveyor.yml
index 4e13aa9..80988cd 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,4 +1,4 @@
-os: Visual Studio 2015 RC
+os: Visual Studio 2015
platform:
- x64
@@ -9,15 +9,7 @@ configuration:
- Release
install:
- - SET PATH=c:\python27;%PATH%
- - SET PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH%
- - git clone --quiet --depth 1 https://chromium.googlesource.com/external/gyp.git deps/gyp
- # note windows requires --generator-output to be absolute
- - python deps/gyp/gyp_main.py protozero.gyp --depth=. -f msvs -G msvs_version=2015
- - set MSBUILD_PLATFORM=%platform%
- - if "%MSBUILD_PLATFORM%" == "x86" set MSBUILD_PLATFORM=Win32
- - msbuild protozero.sln /nologo /p:Configuration=%configuration%;Platform=%MSBUILD_PLATFORM%
- - .\%configuration%\tests.exe
+ - CALL build-appveyor.bat
build: off
test: off
diff --git a/build-appveyor.bat b/build-appveyor.bat
new file mode 100644
index 0000000..8cc7430
--- /dev/null
+++ b/build-appveyor.bat
@@ -0,0 +1,79 @@
+ at ECHO OFF
+SETLOCAL
+SET EL=0
+
+ECHO =========== %~f0 ===========
+
+ECHO platform^: %platform%
+ECHO configuration^: %configuration%
+
+SET MSBUILD_VERBOSITY=normal
+IF NOT "%1"=="" SET MSBUILD_VERBOSITY=%1
+ECHO MSBUILD_VERBOSITY^: %MSBUILD_VERBOSITY%
+
+SET PATH=C:\Program Files\7-Zip;%PATH%
+SET PATH=c:\python27;%PATH%
+SET PATH="C:\Program Files (x86)\MSBuild\14.0\bin";%PATH%
+SET PATH=%~dp0deps\protobuf;%PATH%
+
+REM add unix style "find" to front of PATH
+REM used to glob files in gyp
+IF DEFINED APPVEYOR SET PATH=C:\Program Files\Git\usr\bin;%PATH%
+IF NOT DEFINED APPVEYOR SET PATH=%GIT_INSTALL_ROOT%\bin;%PATH%
+WHERE find
+
+IF EXIST %configuration% ECHO deleting %configuration% && RD /Q /S %configuration%
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+IF EXIST protozero.sln DEL protozero.sln
+IF EXIST protozero.sdf DEL protozero.sdf
+DEL *.vcxproj
+DEL *.vcxproj.filters
+
+IF exist deps\gyp (ECHO gyp already cloned) ELSE (git clone --quiet --depth 1 https://chromium.googlesource.com/external/gyp.git deps/gyp)
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+SET protobuf_sdk=protozero-dep-protobuf-2.6.1.7z
+IF EXIST %protobuf_sdk% (ECHO protobuf already downloaded) ELSE (ECHO downloading protobuf ... && powershell Invoke-WebRequest https://mapbox.s3.amazonaws.com/windows-builds/windows-build-deps/$env:protobuf_sdk -OutFile $pwd\$env:protobuf_sdk)
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+IF EXIST deps\protobuf (ECHO protobuf already extracted) ELSE (CALL 7z x -y %protobuf_sdk% | %windir%\system32\FIND "ing archive")
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+FOR /F %%x in ('find test/ -name "testcase.proto"') DO "deps\protobuf\%platform%\%configuration%\protoc" --cpp_out=. %%x
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+REM note windows requires --generator-output to be absolute
+python deps/gyp/gyp_main.py protozero.gyp --depth=. -f msvs -G msvs_version=2015
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+SET MSBUILD_PLATFORM=%platform%
+IF /I "%MSBUILD_PLATFORM%" == "x86" set MSBUILD_PLATFORM=Win32
+
+msbuild protozero.sln ^
+/nologo ^
+/maxcpucount:%NUMBER_OF_PROCESSORS% ^
+/p:BuildInParellel=true ^
+/p:Configuration=%configuration%;Platform=%MSBUILD_PLATFORM% ^
+/verbosity:%MSBUILD_VERBOSITY% ^
+/consoleloggerparameters:Summary
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+ECHO running %configuration%\%platform%\tests.exe ...
+%configuration%\%platform%\tests.exe
+:: IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+ECHO running %configuration%\%platform%\writer_tests.exe ...
+%configuration%\%platform%\writer_tests.exe
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+GOTO DONE
+
+:ERROR
+ECHO ~~~~~~~~~ ERROR %~f0 ~~~~~~~~~~~
+SET EL=%ERRORLEVEL%
+ECHO ERRORLEVEL^: %EL%
+
+:DONE
+
+ECHO DONE %~f0 %platform% %configuration%
+EXIT /B %EL%
diff --git a/build-local.bat b/build-local.bat
new file mode 100644
index 0000000..62db254
--- /dev/null
+++ b/build-local.bat
@@ -0,0 +1,29 @@
+ at ECHO OFF
+SETLOCAL
+SET EL=0
+
+ECHO =========== %~f0 ===========
+
+SET VERBOSITY_MSBUILD=diagnostic
+IF NOT "%1"=="" SET VERBOSITY_MSBUILD=%1
+SET platform=x64
+SET configuration=Release
+CALL build-appveyor.bat %VERBOSITY_MSBUILD%
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+SET platform=x86
+SET configuration=Debug
+CALL build-appveyor.bat %VERBOSITY_MSBUILD%
+IF %ERRORLEVEL% NEQ 0 GOTO ERROR
+
+GOTO DONE
+
+:ERROR
+ECHO =========== ERROR %~f0 ===========
+ECHO ERRORLEVEL^: %ERRORLEVEL%
+SET EL=%ERRORLEVEL%
+
+:DONE
+ECHO =========== DONE %~f0 ===========
+
+EXIT /b %EL%
diff --git a/common.gypi b/common.gypi
index aa24ac6..2e329aa 100644
--- a/common.gypi
+++ b/common.gypi
@@ -3,11 +3,14 @@
["OS=='win'", {
"target_defaults": {
"default_configuration": "Release_x64",
- #"msbuild_toolset":"CTP_Nov2013",
+ "msvs_configuration_attributes": {
+ "OutputDirectory": "$(SolutionDir)$(Configuration)\\$(PlatformTarget)\\",
+ },
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1, # /EHsc
- "RuntimeTypeInfo": "true" # /GR
+ "RuntimeTypeInfo": "true", # /GR
+ "ObjectFile": "$(SolutionDir)$(Configuration)\\$(PlatformTarget)\\%(RelativeDir)",
}
},
"configurations": {
@@ -16,7 +19,7 @@
"defines": [ "DEBUG","_DEBUG"],
"msvs_settings": {
"VCCLCompilerTool": {
- "RuntimeLibrary": "1", # static debug /MTd
+ "RuntimeLibrary": "3", #0:static release /MT, 1:static debug /MTd, 2:shared /MD, 3:shared debug /MDd
"Optimization": 0, # /Od, no optimization
"MinimalRebuild": "false",
"OmitFramePointers": "false",
@@ -25,24 +28,15 @@
}
},
"Debug_x64": {
+ 'inherit_from': ['Debug_Win32'],
"msvs_configuration_platform": "x64",
- "defines": [ "DEBUG","_DEBUG"],
- "msvs_settings": {
- "VCCLCompilerTool": {
- "RuntimeLibrary": "1", # static debug /MTd
- "Optimization": 0, # /Od, no optimization
- "MinimalRebuild": "false",
- "OmitFramePointers": "false",
- "BasicRuntimeChecks": 3 # /RTC1
- }
- }
},
"Release_Win32": {
"msvs_configuration_platform": "Win32",
"defines": [ "NDEBUG"],
"msvs_settings": {
"VCCLCompilerTool": {
- "RuntimeLibrary": 0, # static release
+ "RuntimeLibrary": "2", #0:static release /MT, 1:static debug /MTd, 2:shared /MD, 3:shared debug /MDd
"Optimization": 3, # /Ox, full optimization
"FavorSizeOrSpeed": 1, # /Ot, favour speed over size
"InlineFunctionExpansion": 2, # /Ob2, inline anything eligible
@@ -70,36 +64,8 @@
}
},
"Release_x64": {
+ 'inherit_from': ['Release_Win32'],
"msvs_configuration_platform": "x64",
- "defines": [ "NDEBUG"],
- "msvs_settings": {
- "VCCLCompilerTool": {
- "RuntimeLibrary": 0, # static release
- "Optimization": 3, # /Ox, full optimization
- "FavorSizeOrSpeed": 1, # /Ot, favour speed over size
- "InlineFunctionExpansion": 2, # /Ob2, inline anything eligible
- "WholeProgramOptimization": "true", # /GL, whole program optimization, needed for LTCG
- "OmitFramePointers": "true",
- "EnableFunctionLevelLinking": "true",
- "EnableIntrinsicFunctions": "true",
- #"AdditionalOptions": [
- # "/MP", # compile across multiple CPUs
- #],
- "DebugInformationFormat": "0"
- },
- "VCLibrarianTool": {
- "AdditionalOptions": [
- "/LTCG" # link time code generation
- ],
- },
- "VCLinkerTool": {
- "LinkTimeCodeGeneration": 1, # link-time code generation
- "OptimizeReferences": 2, # /OPT:REF
- "EnableCOMDATFolding": 2, # /OPT:ICF
- "LinkIncremental": 1, # disable incremental linking
- "GenerateDebugInformation": "false"
- }
- }
}
}
}
diff --git a/include/protozero/byteswap.hpp b/include/protozero/byteswap.hpp
index 29c312a..a018c1c 100644
--- a/include/protozero/byteswap.hpp
+++ b/include/protozero/byteswap.hpp
@@ -19,6 +19,8 @@ documentation.
#include <cstdint>
#include <cassert>
+#include <protozero/config.hpp>
+
namespace protozero {
/**
@@ -35,9 +37,9 @@ inline void byteswap(const char* /*data*/, char* /*result*/) {
*/
template <>
inline void byteswap<4>(const char* data, char* result) {
-# if defined(__GNUC__) || defined(__clang__)
+#ifdef PROTOZERO_USE_BUILTIN_BSWAP
*reinterpret_cast<uint32_t*>(result) = __builtin_bswap32(*reinterpret_cast<const uint32_t*>(data));
-# else
+#else
result[3] = data[0];
result[2] = data[1];
result[1] = data[2];
@@ -50,9 +52,9 @@ inline void byteswap<4>(const char* data, char* result) {
*/
template <>
inline void byteswap<8>(const char* data, char* result) {
-# if defined(__GNUC__) || defined(__clang__)
+#ifdef PROTOZERO_USE_BUILTIN_BSWAP
*reinterpret_cast<uint64_t*>(result) = __builtin_bswap64(*reinterpret_cast<const uint64_t*>(data));
-# else
+#else
result[7] = data[0];
result[6] = data[1];
result[5] = data[2];
diff --git a/include/protozero/config.hpp b/include/protozero/config.hpp
new file mode 100644
index 0000000..4086994
--- /dev/null
+++ b/include/protozero/config.hpp
@@ -0,0 +1,57 @@
+#ifndef PROTOZERO_CONFIG_HPP
+#define PROTOZERO_CONFIG_HPP
+
+/*****************************************************************************
+
+protozero - Minimalistic protocol buffer decoder and encoder in C++.
+
+This file is from https://github.com/mapbox/protozero where you can find more
+documentation.
+
+*****************************************************************************/
+
+#include <cassert>
+
+/**
+ * @file config.hpp
+ *
+ * @brief Contains macro checks for different configurations.
+ */
+
+#define PROTOZERO_LITTLE_ENDIAN 1234
+#define PROTOZERO_BIG_ENDIAN 4321
+
+// Find out which byte order the machine has.
+#if defined(__BYTE_ORDER)
+# if (__BYTE_ORDER == __LITTLE_ENDIAN)
+# define PROTOZERO_BYTE_ORDER PROTOZERO_LITTLE_ENDIAN
+# endif
+# if (__BYTE_ORDER == __BIG_ENDIAN)
+# define PROTOZERO_BYTE_ORDER PROTOZERO_BIG_ENDIAN
+# endif
+#else
+// This probably isn't a very good default, but might do until we figure
+// out something better.
+# define PROTOZERO_BYTE_ORDER PROTOZERO_LITTLE_ENDIAN
+#endif
+
+// On some ARM machines and depending on compiler settings access to unaligned
+// floating point values will result in a SIGBUS. Do not use the bare pointers
+// in this case.
+#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
+# if !defined(__arm__) && !defined(_M_ARM)
+# define PROTOZERO_USE_BARE_POINTER_FOR_PACKED_FIXED
+# endif
+#endif
+
+// Check whether __builtin_bswap is available
+#if defined(__GNUC__) || defined(__clang__)
+# define PROTOZERO_USE_BUILTIN_BSWAP
+#endif
+
+// Wrapper for assert() used for testing
+#ifndef protozero_assert
+# define protozero_assert(x) assert(x)
+#endif
+
+#endif // PROTOZERO_CONFIG_HPP
diff --git a/include/protozero/pbf_reader.hpp b/include/protozero/pbf_reader.hpp
index ac3220c..aced901 100644
--- a/include/protozero/pbf_reader.hpp
+++ b/include/protozero/pbf_reader.hpp
@@ -16,7 +16,6 @@ documentation.
* @brief Contains the pbf_reader class.
*/
-#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -24,19 +23,15 @@ documentation.
#include <string>
#include <utility>
-#include <protozero/pbf_types.hpp>
+#include <protozero/config.hpp>
#include <protozero/exception.hpp>
+#include <protozero/pbf_types.hpp>
#include <protozero/varint.hpp>
-#if __BYTE_ORDER != __LITTLE_ENDIAN
+#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
# include <protozero/byteswap.hpp>
#endif
-/// Wrapper for assert() used for testing
-#ifndef protozero_assert
-# define protozero_assert(x) assert(x)
-#endif
-
namespace protozero {
/**
@@ -77,19 +72,27 @@ class pbf_reader {
// The tag of the current field.
pbf_tag_type m_tag = 0;
+ // Copy N bytes from src to dest on little endian machines, on big endian
+ // swap the bytes in the process.
+ template <int N>
+ static void copy_or_byteswap(const char* src, void* dest) noexcept {
+#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
+ memcpy(dest, src, N);
+#else
+ byteswap<N>(src, reinterpret_cast<char*>(dest));
+#endif
+ }
+
template <typename T>
inline T get_fixed() {
T result;
skip_bytes(sizeof(T));
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- memcpy(&result, m_data - sizeof(T), sizeof(T));
-#else
- byteswap<sizeof(T)>(m_data - sizeof(T), reinterpret_cast<char*>(&result));
-#endif
+ copy_or_byteswap<sizeof(T)>(m_data - sizeof(T), &result);
return result;
}
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef PROTOZERO_USE_BARE_POINTER_FOR_PACKED_FIXED
+
template <typename T>
inline std::pair<const T*, const T*> packed_fixed() {
protozero_assert(tag() != 0 && "call next() before accessing field value");
@@ -128,7 +131,7 @@ class pbf_reader {
T operator*() {
T result;
- byteswap<sizeof(T)>(m_data, reinterpret_cast<char*>(&result));
+ copy_or_byteswap<sizeof(T)>(m_data , &result);
return result;
}
@@ -161,6 +164,7 @@ class pbf_reader {
return std::make_pair(const_fixed_iterator<T>(m_data-len, m_data),
const_fixed_iterator<T>(m_data, m_data));
}
+
#endif
template <typename T> inline T get_varint();
diff --git a/include/protozero/pbf_writer.hpp b/include/protozero/pbf_writer.hpp
index e4e02de..2b78cb8 100644
--- a/include/protozero/pbf_writer.hpp
+++ b/include/protozero/pbf_writer.hpp
@@ -16,7 +16,6 @@ documentation.
* @brief Contains the pbf_writer class.
*/
-#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -24,18 +23,14 @@ documentation.
#include <limits>
#include <string>
+#include <protozero/config.hpp>
#include <protozero/pbf_types.hpp>
#include <protozero/varint.hpp>
-#if __BYTE_ORDER != __LITTLE_ENDIAN
+#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
# include <protozero/byteswap.hpp>
#endif
-/// Wrapper for assert() used for testing
-#ifndef protozero_assert
-# define protozero_assert(x) assert(x)
-#endif
-
namespace protozero {
/**
@@ -71,7 +66,7 @@ class pbf_writer {
inline void add_fixed(T value) {
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
protozero_assert(m_data);
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
m_data->append(reinterpret_cast<const char*>(&value), sizeof(T));
#else
auto size = m_data->size();
@@ -380,7 +375,7 @@ public:
inline void add_bytes(pbf_tag_type tag, const char* value, size_t size) {
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
protozero_assert(m_data);
- assert(size <= std::numeric_limits<pbf_length_type>::max());
+ protozero_assert(size <= std::numeric_limits<pbf_length_type>::max());
add_length_varint(tag, pbf_length_type(size));
m_data->append(value, size);
}
diff --git a/include/protozero/version.hpp b/include/protozero/version.hpp
index f11d303..4f129ac 100644
--- a/include/protozero/version.hpp
+++ b/include/protozero/version.hpp
@@ -12,11 +12,11 @@ documentation.
#define PROTOZERO_VERSION_MAJOR 1
#define PROTOZERO_VERSION_MINOR 2
-#define PROTOZERO_VERSION_PATCH 2
+#define PROTOZERO_VERSION_PATCH 3
#define PROTOZERO_VERSION_CODE (PROTOZERO_VERSION_MAJOR * 10000 + PROTOZERO_VERSION_MINOR * 100 + PROTOZERO_VERSION_PATCH)
-#define PROTOZERO_VERSION_STRING "1.2.2"
+#define PROTOZERO_VERSION_STRING "1.2.3"
#endif // PROTOZERO_VERSION_HPP
diff --git a/protozero.gyp b/protozero.gyp
index 2fa8d0a..c2b4f36 100644
--- a/protozero.gyp
+++ b/protozero.gyp
@@ -7,45 +7,30 @@
"target_name": "tests",
"type": "executable",
"sources": [
- "test/tests.cpp",
- "test/t/basic/test_cases.cpp",
- "test/t/bool/test_cases.cpp",
- "test/t/bytes/test_cases.cpp",
- "test/t/complex/test_cases.cpp",
- "test/t/double/test_cases.cpp",
- "test/t/enum/test_cases.cpp",
- "test/t/fixed32/test_cases.cpp",
- "test/t/fixed64/test_cases.cpp",
- "test/t/float/test_cases.cpp",
- "test/t/int32/test_cases.cpp",
- "test/t/int64/test_cases.cpp",
- "test/t/message/test_cases.cpp",
- "test/t/repeated/test_cases.cpp",
- "test/t/repeated_packed_fixed32/test_cases.cpp",
- "test/t/repeated_packed_fixed64/test_cases.cpp",
- "test/t/repeated_packed_int32/test_cases.cpp",
- "test/t/repeated_packed_int64/test_cases.cpp",
- "test/t/repeated_packed_sfixed32/test_cases.cpp",
- "test/t/repeated_packed_sfixed64/test_cases.cpp",
- "test/t/repeated_packed_sint32/test_cases.cpp",
- "test/t/repeated_packed_sint64/test_cases.cpp",
- "test/t/repeated_packed_uint32/test_cases.cpp",
- "test/t/repeated_packed_uint64/test_cases.cpp",
- "test/t/sfixed32/test_cases.cpp",
- "test/t/sfixed64/test_cases.cpp",
- "test/t/sint32/test_cases.cpp",
- "test/t/sint64/test_cases.cpp",
- "test/t/skip/test_cases.cpp",
- "test/t/string/test_cases.cpp",
- "test/t/tags/test_cases.cpp",
- "test/t/uint32/test_cases.cpp",
- "test/t/uint64/test_cases.cpp",
- "test/t/vector_tile/test_cases.cpp",
- "test/t/zigzag/test_cases.cpp"
+ "<!@(find ./test/ -name '*.cpp' ! -name 'writer_tests.cpp' ! -name 'writer_test_cases.cpp' ! -name 'testcase.cpp')"
],
"include_dirs": [
- "./include/",
- "./test/include/"
+ "./include/",
+ "./test/include/"
+ ]
+ },
+ {
+ "target_name": "writer_tests",
+ "type": "executable",
+ "sources": [
+ "test/writer_tests.cpp",
+ "<!@(find ./test/ -name 'writer_test_cases.cpp')",
+ "<!@(find include/protozero/ -name '*.hpp' ! -name 'config.hpp' ! -name 'pbf_builder.hpp' ! -name 'pbf_message.hpp' ! -name 'version.hpp')",
+ "<!@(find ./test/ -name '*.pb.cc')",
+ ],
+ "include_dirs": [
+ ".",
+ "./include/",
+ "./test/include/",
+ "./deps/protobuf/include"
+ ],
+ "libraries" : [
+ "./deps/protobuf/$(PlatformTarget)/$(Configuration)/libprotobuf-lite.lib"
]
}
]
diff --git a/test/include/testcase.hpp b/test/include/testcase.hpp
index 1005061..8df0584 100644
--- a/test/include/testcase.hpp
+++ b/test/include/testcase.hpp
@@ -11,7 +11,7 @@ std::string write_to_file(const T& msg, const char* filename) {
std::string out;
msg.SerializeToString(&out);
- std::ofstream d(filename);
+ std::ofstream d(filename, std::ios_base::out|std::ios_base::binary);
assert(d.is_open());
d << out;
diff --git a/test/t/basic/test_cases.cpp b/test/t/basic/test_cases.cpp
index ac3c7e3..a728810 100644
--- a/test/t/basic/test_cases.cpp
+++ b/test/t/basic/test_cases.cpp
@@ -12,7 +12,7 @@ TEST_CASE("basic") {
}
SECTION("empty buffer is okay") {
- std::string buffer;
+ const std::string buffer;
protozero::pbf_reader item(buffer);
REQUIRE(item.length() == 0);
diff --git a/test/t/bool/test_cases.cpp b/test/t/bool/test_cases.cpp
index b73a8fd..9a4b0fe 100644
--- a/test/t/bool/test_cases.cpp
+++ b/test/t/bool/test_cases.cpp
@@ -12,7 +12,7 @@ enum class Test : protozero::pbf_tag_type {
TEST_CASE("read bool field using pbf_reader") {
SECTION("false") {
- std::string buffer = load_data("bool/data-false");
+ const std::string buffer = load_data("bool/data-false");
protozero::pbf_reader item(buffer);
@@ -22,7 +22,7 @@ TEST_CASE("read bool field using pbf_reader") {
}
SECTION("true") {
- std::string buffer = load_data("bool/data-true");
+ const std::string buffer = load_data("bool/data-true");
protozero::pbf_reader item(buffer);
@@ -32,7 +32,7 @@ TEST_CASE("read bool field using pbf_reader") {
}
SECTION("also true") {
- std::string buffer = load_data("bool/data-also-true");
+ const std::string buffer = load_data("bool/data-also-true");
protozero::pbf_reader item(buffer);
@@ -42,7 +42,7 @@ TEST_CASE("read bool field using pbf_reader") {
}
SECTION("still true") {
- std::string buffer = load_data("bool/data-still-true");
+ const std::string buffer = load_data("bool/data-still-true");
protozero::pbf_reader item(buffer);
@@ -56,7 +56,7 @@ TEST_CASE("read bool field using pbf_reader") {
TEST_CASE("read bool field using pbf_message") {
SECTION("false") {
- std::string buffer = load_data("bool/data-false");
+ const std::string buffer = load_data("bool/data-false");
protozero::pbf_message<TestBoolean::Test> item(buffer);
@@ -66,7 +66,7 @@ TEST_CASE("read bool field using pbf_message") {
}
SECTION("true") {
- std::string buffer = load_data("bool/data-true");
+ const std::string buffer = load_data("bool/data-true");
protozero::pbf_message<TestBoolean::Test> item(buffer);
@@ -76,7 +76,7 @@ TEST_CASE("read bool field using pbf_message") {
}
SECTION("also true") {
- std::string buffer = load_data("bool/data-also-true");
+ const std::string buffer = load_data("bool/data-also-true");
protozero::pbf_message<TestBoolean::Test> item(buffer);
@@ -86,7 +86,7 @@ TEST_CASE("read bool field using pbf_message") {
}
SECTION("still true") {
- std::string buffer = load_data("bool/data-still-true");
+ const std::string buffer = load_data("bool/data-still-true");
protozero::pbf_message<TestBoolean::Test> item(buffer);
diff --git a/test/t/bytes/test_cases.cpp b/test/t/bytes/test_cases.cpp
index 57791f1..b335b26 100644
--- a/test/t/bytes/test_cases.cpp
+++ b/test/t/bytes/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read bytes field") {
SECTION("empty") {
- std::string buffer = load_data("bytes/data-empty");
+ const std::string buffer = load_data("bytes/data-empty");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read bytes field") {
}
SECTION("one") {
- std::string buffer = load_data("bytes/data-one");
+ const std::string buffer = load_data("bytes/data-one");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read bytes field") {
}
SECTION("string") {
- std::string buffer = load_data("bytes/data-string");
+ const std::string buffer = load_data("bytes/data-string");
protozero::pbf_reader item(buffer);
@@ -34,12 +34,12 @@ TEST_CASE("read bytes field") {
}
SECTION("binary") {
- std::string buffer = load_data("bytes/data-binary");
+ const std::string buffer = load_data("bytes/data-binary");
protozero::pbf_reader item(buffer);
REQUIRE(item.next());
- std::string data = item.get_string();
+ const std::string data = item.get_string();
REQUIRE(data.size() == 3);
REQUIRE(data[0] == char(1));
REQUIRE(data[1] == char(2));
@@ -48,9 +48,9 @@ TEST_CASE("read bytes field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("bytes/data-binary");
+ const std::string buffer = load_data("bytes/data-binary");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_string(), protozero::end_of_buffer_exception);
diff --git a/test/t/complex/test_cases.cpp b/test/t/complex/test_cases.cpp
index ab1b60d..d00a605 100644
--- a/test/t/complex/test_cases.cpp
+++ b/test/t/complex/test_cases.cpp
@@ -22,7 +22,7 @@ enum class Sub : protozero::pbf_tag_type {
TEST_CASE("read complex data using pbf_reader") {
SECTION("minimal") {
- std::string buffer = load_data("complex/data-minimal");
+ const std::string buffer = load_data("complex/data-minimal");
protozero::pbf_reader item(buffer);
@@ -48,7 +48,7 @@ TEST_CASE("read complex data using pbf_reader") {
}
SECTION("some") {
- std::string buffer = load_data("complex/data-some");
+ const std::string buffer = load_data("complex/data-some");
protozero::pbf_reader item(buffer);
@@ -85,7 +85,7 @@ TEST_CASE("read complex data using pbf_reader") {
}
SECTION("all") {
- std::string buffer = load_data("complex/data-all");
+ const std::string buffer = load_data("complex/data-all");
protozero::pbf_reader item(buffer);
@@ -140,7 +140,7 @@ TEST_CASE("read complex data using pbf_reader") {
}
SECTION("skip everything") {
- std::string buffer = load_data("complex/data-all");
+ const std::string buffer = load_data("complex/data-all");
protozero::pbf_reader item(buffer);
@@ -168,7 +168,7 @@ TEST_CASE("read complex data using pbf_reader") {
TEST_CASE("read complex data using pbf_message") {
SECTION("minimal") {
- std::string buffer = load_data("complex/data-minimal");
+ const std::string buffer = load_data("complex/data-minimal");
protozero::pbf_message<TestComplex::Test> item(buffer);
@@ -194,7 +194,7 @@ TEST_CASE("read complex data using pbf_message") {
}
SECTION("some") {
- std::string buffer = load_data("complex/data-some");
+ const std::string buffer = load_data("complex/data-some");
protozero::pbf_message<TestComplex::Test> item(buffer);
@@ -231,7 +231,7 @@ TEST_CASE("read complex data using pbf_message") {
}
SECTION("all") {
- std::string buffer = load_data("complex/data-all");
+ const std::string buffer = load_data("complex/data-all");
protozero::pbf_message<TestComplex::Test> item(buffer);
@@ -286,7 +286,7 @@ TEST_CASE("read complex data using pbf_message") {
}
SECTION("skip everything") {
- std::string buffer = load_data("complex/data-all");
+ const std::string buffer = load_data("complex/data-all");
protozero::pbf_message<TestComplex::Test> item(buffer);
diff --git a/test/t/double/test_cases.cpp b/test/t/double/test_cases.cpp
index b9e1eb3..301e34f 100644
--- a/test/t/double/test_cases.cpp
+++ b/test/t/double/test_cases.cpp
@@ -3,44 +3,55 @@
TEST_CASE("read double field") {
- SECTION("zero") {
- std::string buffer = load_data("double/data-zero");
+ // 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.
- protozero::pbf_reader item(buffer);
+ for (std::string::size_type n = 0; n < 2; ++n) {
- REQUIRE(item.next());
- REQUIRE(item.get_double() == Approx(0.0));
- REQUIRE(!item.next());
- }
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- SECTION("positive") {
- std::string buffer = load_data("double/data-pos");
+ SECTION("zero") {
+ abuffer.append(load_data("double/data-zero"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- protozero::pbf_reader item(buffer);
+ REQUIRE(item.next());
+ REQUIRE(item.get_double() == Approx(0.0));
+ REQUIRE(!item.next());
+ }
- REQUIRE(item.next());
- REQUIRE(item.get_double() == Approx(4.893));
- REQUIRE(!item.next());
- }
+ SECTION("positive") {
+ abuffer.append(load_data("double/data-pos"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("negative") {
- std::string buffer = load_data("double/data-neg");
+ REQUIRE(item.next());
+ REQUIRE(item.get_double() == Approx(4.893));
+ REQUIRE(!item.next());
+ }
- protozero::pbf_reader item(buffer);
+ 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(!item.next());
- }
+ REQUIRE(item.next());
+ REQUIRE(item.get_double() == Approx(-9232.33));
+ REQUIRE(!item.next());
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("double/data-neg");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("double/data-neg"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_double(), protozero::end_of_buffer_exception);
+ 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);
+ }
}
+
}
}
diff --git a/test/t/endian/test_cases.cpp b/test/t/endian/test_cases.cpp
index fc69879..146992d 100644
--- a/test/t/endian/test_cases.cpp
+++ b/test/t/endian/test_cases.cpp
@@ -1,13 +1,13 @@
#include <cstdint>
-#include <protozero/byteswap.hpp>
-
#include <test.hpp>
+#include <protozero/byteswap.hpp>
+
namespace {
- int32_t check_swap_4(int32_t data) {
+ int32_t check_swap_4(const int32_t data) {
int32_t swapped;
int32_t back;
@@ -17,7 +17,7 @@ namespace {
return back;
}
- int64_t check_swap_8(int64_t data) {
+ int64_t check_swap_8(const int64_t data) {
int64_t swapped;
int64_t back;
diff --git a/test/t/enum/test_cases.cpp b/test/t/enum/test_cases.cpp
index 61aca39..3e92d70 100644
--- a/test/t/enum/test_cases.cpp
+++ b/test/t/enum/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read enum field") {
SECTION("zero") {
- std::string buffer = load_data("enum/data-black");
+ const std::string buffer = load_data("enum/data-black");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read enum field") {
}
SECTION("positive") {
- std::string buffer = load_data("enum/data-blue");
+ const std::string buffer = load_data("enum/data-blue");
protozero::pbf_reader item(buffer);
diff --git a/test/t/fixed32/test_cases.cpp b/test/t/fixed32/test_cases.cpp
index 2e56264..5892412 100644
--- a/test/t/fixed32/test_cases.cpp
+++ b/test/t/fixed32/test_cases.cpp
@@ -3,77 +3,85 @@
TEST_CASE("read fixed32 field") {
- SECTION("zero") {
- std::string buffer = load_data("fixed32/data-zero");
-
- protozero::pbf_reader item(buffer);
-
- REQUIRE(item.next());
- REQUIRE(item.get_fixed32() == 0UL);
- REQUIRE(!item.next());
- }
+ // 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.
- SECTION("max-uint") {
- std::string buffer = load_data("fixed32/data-max-uint");
+ for (std::string::size_type n = 0; n < 2; ++n) {
- protozero::pbf_reader item(buffer);
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- REQUIRE(item.next());
- REQUIRE(item.get_fixed32() == std::numeric_limits<uint32_t>::max());
- REQUIRE(!item.next());
- }
+ SECTION("zero") {
+ abuffer.append(load_data("fixed32/data-zero"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("min-uint") {
- std::string buffer = load_data("fixed32/data-min-uint");
+ REQUIRE(item.next());
+ REQUIRE(item.get_fixed32() == 0UL);
+ REQUIRE(!item.next());
+ }
- protozero::pbf_reader item(buffer);
+ SECTION("max-uint") {
+ abuffer.append(load_data("fixed32/data-max-uint"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- REQUIRE(item.get_fixed32() == std::numeric_limits<uint32_t>::min());
- REQUIRE(!item.next());
- }
+ REQUIRE(item.next());
+ REQUIRE(item.get_fixed32() == std::numeric_limits<uint32_t>::max());
+ REQUIRE(!item.next());
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("fixed32/data-min-uint");
+ SECTION("min-uint") {
+ abuffer.append(load_data("fixed32/data-min-uint"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_fixed32(), protozero::end_of_buffer_exception);
+ REQUIRE(item.get_fixed32() == std::numeric_limits<uint32_t>::min());
+ REQUIRE(!item.next());
}
- }
- SECTION("check assert on varint/string access") {
- std::string buffer = load_data("fixed32/data-zero");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("fixed32/data-min-uint"));
- protozero::pbf_reader item(buffer);
+ 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);
+ }
+ }
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_string(), assert_error);
- }
+ SECTION("check assert on varint/string access") {
+ abuffer.append(load_data("fixed32/data-zero"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("assert detecting tag==0") {
- std::string buffer = load_data("fixed32/data-zero");
+ REQUIRE(item.next());
+ REQUIRE_THROWS_AS(item.get_string(), assert_error);
+ }
- protozero::pbf_reader item(buffer);
+ 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(!item.next());
- }
+ REQUIRE_THROWS_AS(item.get_fixed32(), assert_error);
+ REQUIRE(item.next());
+ REQUIRE(item.get_fixed32() == 0UL);
+ REQUIRE_THROWS(item.get_fixed32());
+ REQUIRE(!item.next());
+ }
- SECTION("skip") {
- std::string buffer = load_data("fixed32/data-zero");
+ SECTION("skip") {
+ abuffer.append(load_data("fixed32/data-zero"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- protozero::pbf_reader item(buffer);
+ REQUIRE_THROWS_AS(item.skip(), assert_error);
+ REQUIRE(item.next());
+ item.skip();
+ REQUIRE_THROWS(item.skip());
+ REQUIRE(!item.next());
+ }
- REQUIRE_THROWS_AS(item.skip(), assert_error);
- REQUIRE(item.next());
- item.skip();
- REQUIRE_THROWS(item.skip());
- REQUIRE(!item.next());
}
}
diff --git a/test/t/fixed64/test_cases.cpp b/test/t/fixed64/test_cases.cpp
index 9fbb1ef..8923507 100644
--- a/test/t/fixed64/test_cases.cpp
+++ b/test/t/fixed64/test_cases.cpp
@@ -3,44 +3,55 @@
TEST_CASE("read fixed64 field") {
- SECTION("zero") {
- std::string buffer = load_data("fixed64/data-zero");
+ // 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 int64 will
+ // not be aligned properly. So we test that even in that case the int64
+ // will be extracted properly.
- protozero::pbf_reader item(buffer);
+ for (std::string::size_type n = 0; n < 2; ++n) {
- REQUIRE(item.next());
- REQUIRE(item.get_fixed64() == 0ULL);
- REQUIRE(!item.next());
- }
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- SECTION("max-uint") {
- std::string buffer = load_data("fixed64/data-max-uint");
+ SECTION("zero") {
+ abuffer.append(load_data("fixed64/data-zero"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- protozero::pbf_reader item(buffer);
+ REQUIRE(item.next());
+ REQUIRE(item.get_fixed64() == 0ULL);
+ REQUIRE(!item.next());
+ }
- REQUIRE(item.next());
- REQUIRE(item.get_fixed64() == std::numeric_limits<uint64_t>::max());
- REQUIRE(!item.next());
- }
+ SECTION("max-uint") {
+ abuffer.append(load_data("fixed64/data-max-uint"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("min-uint") {
- std::string buffer = load_data("fixed64/data-min-uint");
+ REQUIRE(item.next());
+ REQUIRE(item.get_fixed64() == std::numeric_limits<uint64_t>::max());
+ REQUIRE(!item.next());
+ }
- protozero::pbf_reader item(buffer);
+ SECTION("min-uint") {
+ abuffer.append(load_data("fixed64/data-min-uint"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- REQUIRE(item.get_fixed64() == std::numeric_limits<uint64_t>::min());
- REQUIRE(!item.next());
- }
+ REQUIRE(item.next());
+ REQUIRE(item.get_fixed64() == std::numeric_limits<uint64_t>::min());
+ REQUIRE(!item.next());
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("fixed64/data-min-uint");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("fixed64/data-min-uint"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_fixed64(), protozero::end_of_buffer_exception);
+ 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);
+ }
}
+
}
}
diff --git a/test/t/float/test_cases.cpp b/test/t/float/test_cases.cpp
index 48721c1..96fd84c 100644
--- a/test/t/float/test_cases.cpp
+++ b/test/t/float/test_cases.cpp
@@ -3,44 +3,55 @@
TEST_CASE("read float field") {
- SECTION("zero") {
- std::string buffer = load_data("float/data-zero");
+ // 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.
- protozero::pbf_reader item(buffer);
+ for (std::string::size_type n = 0; n < 2; ++n) {
- REQUIRE(item.next());
- REQUIRE(item.get_float() == Approx(0.0f));
- REQUIRE(!item.next());
- }
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- SECTION("positive") {
- std::string buffer = load_data("float/data-pos");
+ SECTION("zero") {
+ abuffer.append(load_data("float/data-zero"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- protozero::pbf_reader item(buffer);
+ REQUIRE(item.next());
+ REQUIRE(item.get_float() == Approx(0.0f));
+ REQUIRE(!item.next());
+ }
- REQUIRE(item.next());
- REQUIRE(item.get_float() == Approx(5.34f));
- REQUIRE(!item.next());
- }
+ SECTION("positive") {
+ abuffer.append(load_data("float/data-pos"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("negative") {
- std::string buffer = load_data("float/data-neg");
+ REQUIRE(item.next());
+ REQUIRE(item.get_float() == Approx(5.34f));
+ REQUIRE(!item.next());
+ }
- protozero::pbf_reader item(buffer);
+ SECTION("negative") {
+ abuffer.append(load_data("float/data-neg"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- REQUIRE(item.get_float() == Approx(-1.71f));
- REQUIRE(!item.next());
- }
+ REQUIRE(item.next());
+ REQUIRE(item.get_float() == Approx(-1.71f));
+ REQUIRE(!item.next());
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("float/data-neg");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("float/data-neg"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_float(), protozero::end_of_buffer_exception);
+ 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);
+ }
}
+
}
}
diff --git a/test/t/int32/test_cases.cpp b/test/t/int32/test_cases.cpp
index 7af603d..04a83b3 100644
--- a/test/t/int32/test_cases.cpp
+++ b/test/t/int32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read int32 field") {
SECTION("zero") {
- std::string buffer = load_data("int32/data-zero");
+ const std::string buffer = load_data("int32/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read int32 field") {
}
SECTION("positive") {
- std::string buffer = load_data("int32/data-pos");
+ const std::string buffer = load_data("int32/data-pos");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read int32 field") {
}
SECTION("negative") {
- std::string buffer = load_data("int32/data-neg");
+ const std::string buffer = load_data("int32/data-neg");
protozero::pbf_reader item(buffer);
@@ -34,7 +34,7 @@ TEST_CASE("read int32 field") {
}
SECTION("max") {
- std::string buffer = load_data("int32/data-max");
+ const std::string buffer = load_data("int32/data-max");
protozero::pbf_reader item(buffer);
@@ -44,7 +44,7 @@ TEST_CASE("read int32 field") {
}
SECTION("min64") {
- std::string buffer = load_data("int32/data-min");
+ const std::string buffer = load_data("int32/data-min");
protozero::pbf_reader item(buffer);
@@ -54,7 +54,7 @@ TEST_CASE("read int32 field") {
}
SECTION("min") {
- std::string buffer = load_data("int32/data-min");
+ const std::string buffer = load_data("int32/data-min");
protozero::pbf_reader item(buffer);
@@ -64,9 +64,9 @@ TEST_CASE("read int32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("int32/data-min");
+ const std::string buffer = load_data("int32/data-min");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_int32(), protozero::end_of_buffer_exception);
@@ -74,7 +74,7 @@ TEST_CASE("read int32 field") {
}
SECTION("check assert on string/fixed int access") {
- std::string buffer = load_data("int32/data-zero");
+ const std::string buffer = load_data("int32/data-zero");
protozero::pbf_reader item(buffer);
diff --git a/test/t/int64/test_cases.cpp b/test/t/int64/test_cases.cpp
index cb815ac..0ee4060 100644
--- a/test/t/int64/test_cases.cpp
+++ b/test/t/int64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read int64 field") {
SECTION("zero") {
- std::string buffer = load_data("int64/data-zero");
+ const std::string buffer = load_data("int64/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read int64 field") {
}
SECTION("positive") {
- std::string buffer = load_data("int64/data-pos");
+ const std::string buffer = load_data("int64/data-pos");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read int64 field") {
}
SECTION("negative") {
- std::string buffer = load_data("int64/data-neg");
+ const std::string buffer = load_data("int64/data-neg");
protozero::pbf_reader item(buffer);
@@ -34,7 +34,7 @@ TEST_CASE("read int64 field") {
}
SECTION("max") {
- std::string buffer = load_data("int64/data-max");
+ const std::string buffer = load_data("int64/data-max");
protozero::pbf_reader item(buffer);
@@ -44,7 +44,7 @@ TEST_CASE("read int64 field") {
}
SECTION("min") {
- std::string buffer = load_data("int64/data-min");
+ const std::string buffer = load_data("int64/data-min");
protozero::pbf_reader item(buffer);
@@ -54,9 +54,9 @@ TEST_CASE("read int64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("int64/data-min");
+ const std::string buffer = load_data("int64/data-min");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_int64(), protozero::end_of_buffer_exception);
@@ -64,7 +64,7 @@ TEST_CASE("read int64 field") {
}
SECTION("varint overflow") {
- std::string buffer = load_data("int64/data-overflow");
+ const std::string buffer = load_data("int64/data-overflow");
protozero::pbf_reader item(buffer);
diff --git a/test/t/message/test_cases.cpp b/test/t/message/test_cases.cpp
index ef92064..2298806 100644
--- a/test/t/message/test_cases.cpp
+++ b/test/t/message/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read message field") {
SECTION("string") {
- std::string buffer = load_data("message/data-message");
+ const std::string buffer = load_data("message/data-message");
protozero::pbf_reader item(buffer);
@@ -18,9 +18,9 @@ TEST_CASE("read message field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("message/data-message");
+ const std::string buffer = load_data("message/data-message");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_string(), protozero::end_of_buffer_exception);
@@ -28,7 +28,7 @@ TEST_CASE("read message field") {
}
SECTION("optional contents of message - empty") {
- std::string buffer = load_data("message/data-opt-empty");
+ const std::string buffer = load_data("message/data-opt-empty");
protozero::pbf_reader item(buffer);
@@ -36,7 +36,7 @@ TEST_CASE("read message field") {
}
SECTION("string") {
- std::string buffer = load_data("message/data-opt-element");
+ const std::string buffer = load_data("message/data-opt-element");
protozero::pbf_reader item(buffer);
diff --git a/test/t/nested/test_cases.cpp b/test/t/nested/test_cases.cpp
index bf74bc9..bfc4fdd 100644
--- a/test/t/nested/test_cases.cpp
+++ b/test/t/nested/test_cases.cpp
@@ -80,14 +80,14 @@ inline void check_empty(protozero::pbf_reader message) {
TEST_CASE("read nested message fields") {
SECTION("string") {
- std::string buffer = load_data("nested/data-message");
+ const std::string buffer = load_data("nested/data-message");
protozero::pbf_reader message(buffer);
check(message);
}
SECTION("no submessage") {
- std::string buffer = load_data("nested/data-no-message");
+ const std::string buffer = load_data("nested/data-no-message");
protozero::pbf_reader message(buffer);
check_empty(message);
diff --git a/test/t/repeated/test_cases.cpp b/test/t/repeated/test_cases.cpp
index 9a6148c..5671dbb 100644
--- a/test/t/repeated/test_cases.cpp
+++ b/test/t/repeated/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated fields") {
SECTION("empty") {
- std::string buffer = load_data("repeated/data-empty");
+ const std::string buffer = load_data("repeated/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated fields") {
}
SECTION("one") {
- std::string buffer = load_data("repeated/data-one");
+ const std::string buffer = load_data("repeated/data-one");
protozero::pbf_reader item(buffer);
@@ -22,7 +22,7 @@ TEST_CASE("read repeated fields") {
}
SECTION("many") {
- std::string buffer = load_data("repeated/data-many");
+ const std::string buffer = load_data("repeated/data-many");
protozero::pbf_reader item(buffer);
@@ -45,9 +45,9 @@ TEST_CASE("read repeated fields") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated/data-one");
+ const std::string buffer = load_data("repeated/data-one");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_int32(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_bool/test_cases.cpp b/test/t/repeated_packed_bool/test_cases.cpp
index 7d3424e..574d538 100644
--- a/test/t/repeated_packed_bool/test_cases.cpp
+++ b/test/t/repeated_packed_bool/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed bool field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_bool/data-empty");
+ const std::string buffer = load_data("repeated_packed_bool/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed bool field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_bool/data-one");
+ const std::string buffer = load_data("repeated_packed_bool/data-one");
protozero::pbf_reader item(buffer);
@@ -26,7 +26,7 @@ TEST_CASE("read repeated packed bool field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_bool/data-many");
+ const std::string buffer = load_data("repeated_packed_bool/data-many");
protozero::pbf_reader item(buffer);
@@ -44,9 +44,9 @@ TEST_CASE("read repeated packed bool field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_bool/data-many");
+ const std::string buffer = load_data("repeated_packed_bool/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_bool(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_double/test_cases.cpp b/test/t/repeated_packed_double/test_cases.cpp
index 7fc7c52..059d4b8 100644
--- a/test/t/repeated_packed_double/test_cases.cpp
+++ b/test/t/repeated_packed_double/test_cases.cpp
@@ -3,53 +3,64 @@
TEST_CASE("read repeated packed double field") {
- SECTION("empty") {
- std::string buffer = load_data("repeated_packed_double/data-empty");
-
- protozero::pbf_reader item(buffer);
+ // 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 doubles will
+ // not be aligned properly. So we test that even in that case the doubles
+ // will be extracted properly.
- REQUIRE(!item.next());
- }
+ for (std::string::size_type n = 0; n < 2; ++n) {
- SECTION("one") {
- std::string buffer = load_data("repeated_packed_double/data-one");
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- protozero::pbf_reader item(buffer);
+ SECTION("empty") {
+ abuffer.append(load_data("repeated_packed_double/data-empty"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- auto it_pair = item.get_packed_double();
- REQUIRE(!item.next());
+ REQUIRE(!item.next());
+ }
- REQUIRE(*it_pair.first == 17.34);
- REQUIRE(++it_pair.first == it_pair.second);
- }
+ SECTION("one") {
+ abuffer.append(load_data("repeated_packed_double/data-one"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("many") {
- std::string buffer = load_data("repeated_packed_double/data-many");
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_double();
+ REQUIRE(!item.next());
- protozero::pbf_reader item(buffer);
+ REQUIRE(*it_pair.first == 17.34);
+ REQUIRE(++it_pair.first == it_pair.second);
+ }
- REQUIRE(item.next());
- auto it_pair = item.get_packed_double();
- REQUIRE(!item.next());
+ SECTION("many") {
+ abuffer.append(load_data("repeated_packed_double/data-many"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- auto it = it_pair.first;
- REQUIRE(*it++ == 17.34);
- REQUIRE(*it++ == 0.0);
- REQUIRE(*it++ == 1.0);
- REQUIRE(*it++ == std::numeric_limits<double>::min());
- REQUIRE(*it++ == std::numeric_limits<double>::max());
- REQUIRE(it == it_pair.second);
- }
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_double();
+ REQUIRE(!item.next());
+
+ auto it = it_pair.first;
+ REQUIRE(*it++ == 17.34);
+ REQUIRE(*it++ == 0.0);
+ REQUIRE(*it++ == 1.0);
+ REQUIRE(*it++ == std::numeric_limits<double>::min());
+ REQUIRE(*it++ == std::numeric_limits<double>::max());
+ REQUIRE(it == it_pair.second);
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_double/data-many");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("repeated_packed_double/data-many"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_packed_double(), protozero::end_of_buffer_exception);
+ for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
+ protozero::pbf_reader item(abuffer.data() + n, i);
+ REQUIRE(item.next());
+ REQUIRE_THROWS_AS(item.get_packed_double(), protozero::end_of_buffer_exception);
+ }
}
+
}
}
diff --git a/test/t/repeated_packed_enum/test_cases.cpp b/test/t/repeated_packed_enum/test_cases.cpp
index f475a94..be1473a 100644
--- a/test/t/repeated_packed_enum/test_cases.cpp
+++ b/test/t/repeated_packed_enum/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed enum field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_enum/data-empty");
+ const std::string buffer = load_data("repeated_packed_enum/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed enum field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_enum/data-one");
+ const std::string buffer = load_data("repeated_packed_enum/data-one");
protozero::pbf_reader item(buffer);
@@ -26,7 +26,7 @@ TEST_CASE("read repeated packed enum field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_enum/data-many");
+ const std::string buffer = load_data("repeated_packed_enum/data-many");
protozero::pbf_reader item(buffer);
@@ -43,9 +43,9 @@ TEST_CASE("read repeated packed enum field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_enum/data-many");
+ const std::string buffer = load_data("repeated_packed_enum/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_enum(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_fixed32/test_cases.cpp b/test/t/repeated_packed_fixed32/test_cases.cpp
index 266f310..4a02eec 100644
--- a/test/t/repeated_packed_fixed32/test_cases.cpp
+++ b/test/t/repeated_packed_fixed32/test_cases.cpp
@@ -3,52 +3,63 @@
TEST_CASE("read repeated packed fixed32 field") {
- SECTION("empty") {
- std::string buffer = load_data("repeated_packed_fixed32/data-empty");
-
- protozero::pbf_reader item(buffer);
+ // 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 int32s will
+ // not be aligned properly. So we test that even in that case the int32s
+ // will be extracted properly.
- REQUIRE(!item.next());
- }
+ for (std::string::size_type n = 0; n < 2; ++n) {
- SECTION("one") {
- std::string buffer = load_data("repeated_packed_fixed32/data-one");
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- protozero::pbf_reader item(buffer);
+ SECTION("empty") {
+ abuffer.append(load_data("repeated_packed_fixed32/data-empty"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- auto it_pair = item.get_packed_fixed32();
- REQUIRE(!item.next());
+ REQUIRE(!item.next());
+ }
- REQUIRE(*it_pair.first == 17UL);
- REQUIRE(++it_pair.first == it_pair.second);
- }
+ SECTION("one") {
+ abuffer.append(load_data("repeated_packed_fixed32/data-one"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("many") {
- std::string buffer = load_data("repeated_packed_fixed32/data-many");
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_fixed32();
+ REQUIRE(!item.next());
- protozero::pbf_reader item(buffer);
+ REQUIRE(*it_pair.first == 17UL);
+ REQUIRE(++it_pair.first == it_pair.second);
+ }
- REQUIRE(item.next());
- auto it_pair = item.get_packed_fixed32();
- REQUIRE(!item.next());
+ SECTION("many") {
+ abuffer.append(load_data("repeated_packed_fixed32/data-many"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- auto it = it_pair.first;
- REQUIRE(*it++ == 17UL);
- REQUIRE(*it++ == 0UL);
- REQUIRE(*it++ == 1UL);
- REQUIRE(*it++ == std::numeric_limits<uint32_t>::max());
- REQUIRE(it == it_pair.second);
- }
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_fixed32();
+ REQUIRE(!item.next());
+
+ auto it = it_pair.first;
+ REQUIRE(*it++ == 17UL);
+ REQUIRE(*it++ == 0UL);
+ REQUIRE(*it++ == 1UL);
+ REQUIRE(*it++ == std::numeric_limits<uint32_t>::max());
+ REQUIRE(it == it_pair.second);
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_fixed32/data-many");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("repeated_packed_fixed32/data-many"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_packed_fixed32(), protozero::end_of_buffer_exception);
+ for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
+ protozero::pbf_reader item(abuffer.data() + n, i);
+ REQUIRE(item.next());
+ REQUIRE_THROWS_AS(item.get_packed_fixed32(), protozero::end_of_buffer_exception);
+ }
}
+
}
}
diff --git a/test/t/repeated_packed_fixed64/test_cases.cpp b/test/t/repeated_packed_fixed64/test_cases.cpp
index 5bb59d5..97c14ad 100644
--- a/test/t/repeated_packed_fixed64/test_cases.cpp
+++ b/test/t/repeated_packed_fixed64/test_cases.cpp
@@ -3,52 +3,63 @@
TEST_CASE("read repeated packed fixed64 field") {
- SECTION("empty") {
- std::string buffer = load_data("repeated_packed_fixed64/data-empty");
-
- protozero::pbf_reader item(buffer);
+ // 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 int64s will
+ // not be aligned properly. So we test that even in that case the int64s
+ // will be extracted properly.
- REQUIRE(!item.next());
- }
+ for (std::string::size_type n = 0; n < 2; ++n) {
- SECTION("one") {
- std::string buffer = load_data("repeated_packed_fixed64/data-one");
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- protozero::pbf_reader item(buffer);
+ SECTION("empty") {
+ abuffer.append(load_data("repeated_packed_fixed64/data-empty"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- auto it_pair = item.get_packed_fixed64();
- REQUIRE(!item.next());
+ REQUIRE(!item.next());
+ }
- REQUIRE(*it_pair.first == 17ULL);
- REQUIRE(++it_pair.first == it_pair.second);
- }
+ SECTION("one") {
+ abuffer.append(load_data("repeated_packed_fixed64/data-one"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("many") {
- std::string buffer = load_data("repeated_packed_fixed64/data-many");
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_fixed64();
+ REQUIRE(!item.next());
- protozero::pbf_reader item(buffer);
+ REQUIRE(*it_pair.first == 17ULL);
+ REQUIRE(++it_pair.first == it_pair.second);
+ }
- REQUIRE(item.next());
- auto it_pair = item.get_packed_fixed64();
- REQUIRE(!item.next());
+ SECTION("many") {
+ abuffer.append(load_data("repeated_packed_fixed64/data-many"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- auto it = it_pair.first;
- REQUIRE(*it++ == 17ULL);
- REQUIRE(*it++ == 0ULL);
- REQUIRE(*it++ == 1ULL);
- REQUIRE(*it++ == std::numeric_limits<uint64_t>::max());
- REQUIRE(it == it_pair.second);
- }
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_fixed64();
+ REQUIRE(!item.next());
+
+ auto it = it_pair.first;
+ REQUIRE(*it++ == 17ULL);
+ REQUIRE(*it++ == 0ULL);
+ REQUIRE(*it++ == 1ULL);
+ REQUIRE(*it++ == std::numeric_limits<uint64_t>::max());
+ REQUIRE(it == it_pair.second);
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_fixed64/data-many");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("repeated_packed_fixed64/data-many"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_packed_fixed64(), protozero::end_of_buffer_exception);
+ for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
+ protozero::pbf_reader item(abuffer.data() + n, i);
+ REQUIRE(item.next());
+ REQUIRE_THROWS_AS(item.get_packed_fixed64(), protozero::end_of_buffer_exception);
+ }
}
+
}
}
diff --git a/test/t/repeated_packed_float/test_cases.cpp b/test/t/repeated_packed_float/test_cases.cpp
index ddbc5fa..9ae03eb 100644
--- a/test/t/repeated_packed_float/test_cases.cpp
+++ b/test/t/repeated_packed_float/test_cases.cpp
@@ -3,53 +3,64 @@
TEST_CASE("read repeated packed float field") {
- SECTION("empty") {
- std::string buffer = load_data("repeated_packed_float/data-empty");
-
- protozero::pbf_reader item(buffer);
+ // 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 floats will
+ // not be aligned properly. So we test that even in that case the floats
+ // will be extracted properly.
- REQUIRE(!item.next());
- }
+ for (std::string::size_type n = 0; n < 2; ++n) {
- SECTION("one") {
- std::string buffer = load_data("repeated_packed_float/data-one");
+ std::string abuffer;
+ abuffer.reserve(1000);
+ abuffer.append(n, '\0');
- protozero::pbf_reader item(buffer);
+ SECTION("empty") {
+ abuffer.append(load_data("repeated_packed_float/data-empty"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- REQUIRE(item.next());
- auto it_pair = item.get_packed_float();
- REQUIRE(!item.next());
+ REQUIRE(!item.next());
+ }
- REQUIRE(*it_pair.first == 17.34f);
- REQUIRE(++it_pair.first == it_pair.second);
- }
+ SECTION("one") {
+ abuffer.append(load_data("repeated_packed_float/data-one"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- SECTION("many") {
- std::string buffer = load_data("repeated_packed_float/data-many");
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_float();
+ REQUIRE(!item.next());
- protozero::pbf_reader item(buffer);
+ REQUIRE(*it_pair.first == 17.34f);
+ REQUIRE(++it_pair.first == it_pair.second);
+ }
- REQUIRE(item.next());
- auto it_pair = item.get_packed_float();
- REQUIRE(!item.next());
+ SECTION("many") {
+ abuffer.append(load_data("repeated_packed_float/data-many"));
+ protozero::pbf_reader item(abuffer.data() + n, abuffer.size() - n);
- auto it = it_pair.first;
- REQUIRE(*it++ == 17.34f);
- REQUIRE(*it++ == 0.0f);
- REQUIRE(*it++ == 1.0f);
- REQUIRE(*it++ == std::numeric_limits<float>::min());
- REQUIRE(*it++ == std::numeric_limits<float>::max());
- REQUIRE(it == it_pair.second);
- }
+ REQUIRE(item.next());
+ auto it_pair = item.get_packed_float();
+ REQUIRE(!item.next());
+
+ auto it = it_pair.first;
+ REQUIRE(*it++ == 17.34f);
+ REQUIRE(*it++ == 0.0f);
+ REQUIRE(*it++ == 1.0f);
+ REQUIRE(*it++ == std::numeric_limits<float>::min());
+ REQUIRE(*it++ == std::numeric_limits<float>::max());
+ REQUIRE(it == it_pair.second);
+ }
- SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_float/data-many");
+ SECTION("end_of_buffer") {
+ abuffer.append(load_data("repeated_packed_float/data-many"));
- for (size_t i=1; i < buffer.size(); ++i) {
- protozero::pbf_reader item(buffer.data(), i);
- REQUIRE(item.next());
- REQUIRE_THROWS_AS(item.get_packed_float(), protozero::end_of_buffer_exception);
+ for (std::string::size_type i = 1; i < abuffer.size() - n; ++i) {
+ protozero::pbf_reader item(abuffer.data() + n, i);
+ REQUIRE(item.next());
+ REQUIRE_THROWS_AS(item.get_packed_float(), protozero::end_of_buffer_exception);
+ }
}
+
}
}
diff --git a/test/t/repeated_packed_int32/test_cases.cpp b/test/t/repeated_packed_int32/test_cases.cpp
index dc369a2..e27cee9 100644
--- a/test/t/repeated_packed_int32/test_cases.cpp
+++ b/test/t/repeated_packed_int32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed int32 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_int32/data-empty");
+ const std::string buffer = load_data("repeated_packed_int32/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed int32 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_int32/data-one");
+ const std::string buffer = load_data("repeated_packed_int32/data-one");
protozero::pbf_reader item(buffer);
@@ -26,7 +26,7 @@ TEST_CASE("read repeated packed int32 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_int32/data-many");
+ const std::string buffer = load_data("repeated_packed_int32/data-many");
protozero::pbf_reader item(buffer);
@@ -46,9 +46,9 @@ TEST_CASE("read repeated packed int32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_int32/data-many");
+ const std::string buffer = load_data("repeated_packed_int32/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_int32(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_int64/test_cases.cpp b/test/t/repeated_packed_int64/test_cases.cpp
index 98dfb6a..9afda2a 100644
--- a/test/t/repeated_packed_int64/test_cases.cpp
+++ b/test/t/repeated_packed_int64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed int64 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_int64/data-empty");
+ const std::string buffer = load_data("repeated_packed_int64/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed int64 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_int64/data-one");
+ const std::string buffer = load_data("repeated_packed_int64/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed int64 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_int64/data-many");
+ const std::string buffer = load_data("repeated_packed_int64/data-many");
protozero::pbf_reader item(buffer);
@@ -44,9 +44,9 @@ TEST_CASE("read repeated packed int64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_int64/data-many");
+ const std::string buffer = load_data("repeated_packed_int64/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_int64(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_sfixed32/test_cases.cpp b/test/t/repeated_packed_sfixed32/test_cases.cpp
index 2ccf3cb..34ace54 100644
--- a/test/t/repeated_packed_sfixed32/test_cases.cpp
+++ b/test/t/repeated_packed_sfixed32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed sfixed32 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_sfixed32/data-empty");
+ const std::string buffer = load_data("repeated_packed_sfixed32/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed sfixed32 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_sfixed32/data-one");
+ const std::string buffer = load_data("repeated_packed_sfixed32/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed sfixed32 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_sfixed32/data-many");
+ const std::string buffer = load_data("repeated_packed_sfixed32/data-many");
protozero::pbf_reader item(buffer);
@@ -44,9 +44,9 @@ TEST_CASE("read repeated packed sfixed32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_sfixed32/data-many");
+ const std::string buffer = load_data("repeated_packed_sfixed32/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_sfixed32(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_sfixed64/test_cases.cpp b/test/t/repeated_packed_sfixed64/test_cases.cpp
index 08361b2..ecce063 100644
--- a/test/t/repeated_packed_sfixed64/test_cases.cpp
+++ b/test/t/repeated_packed_sfixed64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed sfixed64 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_sfixed64/data-empty");
+ const std::string buffer = load_data("repeated_packed_sfixed64/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed sfixed64 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_sfixed64/data-one");
+ const std::string buffer = load_data("repeated_packed_sfixed64/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed sfixed64 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_sfixed64/data-many");
+ const std::string buffer = load_data("repeated_packed_sfixed64/data-many");
protozero::pbf_reader item(buffer);
@@ -44,9 +44,9 @@ TEST_CASE("read repeated packed sfixed64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_sfixed64/data-many");
+ const std::string buffer = load_data("repeated_packed_sfixed64/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_sfixed64(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_sint32/test_cases.cpp b/test/t/repeated_packed_sint32/test_cases.cpp
index 23bbc41..c2e6c7f 100644
--- a/test/t/repeated_packed_sint32/test_cases.cpp
+++ b/test/t/repeated_packed_sint32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed sint32 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_sint32/data-empty");
+ const std::string buffer = load_data("repeated_packed_sint32/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed sint32 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_sint32/data-one");
+ const std::string buffer = load_data("repeated_packed_sint32/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed sint32 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_sint32/data-many");
+ const std::string buffer = load_data("repeated_packed_sint32/data-many");
protozero::pbf_reader item(buffer);
@@ -44,9 +44,9 @@ TEST_CASE("read repeated packed sint32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_sint32/data-many");
+ const std::string buffer = load_data("repeated_packed_sint32/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_sint32(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_sint64/test_cases.cpp b/test/t/repeated_packed_sint64/test_cases.cpp
index 558f68d..7fa24a0 100644
--- a/test/t/repeated_packed_sint64/test_cases.cpp
+++ b/test/t/repeated_packed_sint64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed sint64 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_sint64/data-empty");
+ const std::string buffer = load_data("repeated_packed_sint64/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed sint64 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_sint64/data-one");
+ const std::string buffer = load_data("repeated_packed_sint64/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed sint64 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_sint64/data-many");
+ const std::string buffer = load_data("repeated_packed_sint64/data-many");
protozero::pbf_reader item(buffer);
@@ -44,9 +44,9 @@ TEST_CASE("read repeated packed sint64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_sint64/data-many");
+ const std::string buffer = load_data("repeated_packed_sint64/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_sint64(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_uint32/test_cases.cpp b/test/t/repeated_packed_uint32/test_cases.cpp
index a842402..dc70ebe 100644
--- a/test/t/repeated_packed_uint32/test_cases.cpp
+++ b/test/t/repeated_packed_uint32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed uint32 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_uint32/data-empty");
+ const std::string buffer = load_data("repeated_packed_uint32/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed uint32 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_uint32/data-one");
+ const std::string buffer = load_data("repeated_packed_uint32/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed uint32 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_uint32/data-many");
+ const std::string buffer = load_data("repeated_packed_uint32/data-many");
protozero::pbf_reader item(buffer);
@@ -42,9 +42,9 @@ TEST_CASE("read repeated packed uint32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_uint32/data-many");
+ const std::string buffer = load_data("repeated_packed_uint32/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_uint32(), protozero::end_of_buffer_exception);
diff --git a/test/t/repeated_packed_uint64/test_cases.cpp b/test/t/repeated_packed_uint64/test_cases.cpp
index 2fdf1c4..6880106 100644
--- a/test/t/repeated_packed_uint64/test_cases.cpp
+++ b/test/t/repeated_packed_uint64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read repeated packed uint64 field") {
SECTION("empty") {
- std::string buffer = load_data("repeated_packed_uint64/data-empty");
+ const std::string buffer = load_data("repeated_packed_uint64/data-empty");
protozero::pbf_reader item(buffer);
@@ -12,7 +12,7 @@ TEST_CASE("read repeated packed uint64 field") {
}
SECTION("one") {
- std::string buffer = load_data("repeated_packed_uint64/data-one");
+ const std::string buffer = load_data("repeated_packed_uint64/data-one");
protozero::pbf_reader item(buffer);
@@ -25,7 +25,7 @@ TEST_CASE("read repeated packed uint64 field") {
}
SECTION("many") {
- std::string buffer = load_data("repeated_packed_uint64/data-many");
+ const std::string buffer = load_data("repeated_packed_uint64/data-many");
protozero::pbf_reader item(buffer);
@@ -42,9 +42,9 @@ TEST_CASE("read repeated packed uint64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("repeated_packed_uint64/data-many");
+ const std::string buffer = load_data("repeated_packed_uint64/data-many");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_packed_uint64(), protozero::end_of_buffer_exception);
diff --git a/test/t/sfixed32/test_cases.cpp b/test/t/sfixed32/test_cases.cpp
index 70e251c..e2471f6 100644
--- a/test/t/sfixed32/test_cases.cpp
+++ b/test/t/sfixed32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read sfixed32 field") {
SECTION("zero") {
- std::string buffer = load_data("sfixed32/data-zero");
+ const std::string buffer = load_data("sfixed32/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read sfixed32 field") {
}
SECTION("max-int") {
- std::string buffer = load_data("sfixed32/data-max-int");
+ const std::string buffer = load_data("sfixed32/data-max-int");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read sfixed32 field") {
}
SECTION("min-int") {
- std::string buffer = load_data("sfixed32/data-min-int");
+ const std::string buffer = load_data("sfixed32/data-min-int");
protozero::pbf_reader item(buffer);
@@ -34,9 +34,9 @@ TEST_CASE("read sfixed32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("sfixed32/data-min-int");
+ const std::string buffer = load_data("sfixed32/data-min-int");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_sfixed32(), protozero::end_of_buffer_exception);
diff --git a/test/t/sfixed64/test_cases.cpp b/test/t/sfixed64/test_cases.cpp
index ae8ca60..cecf273 100644
--- a/test/t/sfixed64/test_cases.cpp
+++ b/test/t/sfixed64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read sfixed64 field") {
SECTION("zero") {
- std::string buffer = load_data("sfixed64/data-zero");
+ const std::string buffer = load_data("sfixed64/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read sfixed64 field") {
}
SECTION("max-int") {
- std::string buffer = load_data("sfixed64/data-max-int");
+ const std::string buffer = load_data("sfixed64/data-max-int");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read sfixed64 field") {
}
SECTION("min-int") {
- std::string buffer = load_data("sfixed64/data-min-int");
+ const std::string buffer = load_data("sfixed64/data-min-int");
protozero::pbf_reader item(buffer);
@@ -34,9 +34,9 @@ TEST_CASE("read sfixed64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("sfixed64/data-min-int");
+ const std::string buffer = load_data("sfixed64/data-min-int");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_sfixed64(), protozero::end_of_buffer_exception);
diff --git a/test/t/sint32/test_cases.cpp b/test/t/sint32/test_cases.cpp
index b75e1dc..68bd9ef 100644
--- a/test/t/sint32/test_cases.cpp
+++ b/test/t/sint32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read sint32 field") {
SECTION("zero") {
- std::string buffer = load_data("sint32/data-zero");
+ const std::string buffer = load_data("sint32/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read sint32 field") {
}
SECTION("positive") {
- std::string buffer = load_data("sint32/data-pos");
+ const std::string buffer = load_data("sint32/data-pos");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read sint32 field") {
}
SECTION("negative") {
- std::string buffer = load_data("sint32/data-neg");
+ const std::string buffer = load_data("sint32/data-neg");
protozero::pbf_reader item(buffer);
@@ -34,7 +34,7 @@ TEST_CASE("read sint32 field") {
}
SECTION("max") {
- std::string buffer = load_data("sint32/data-max");
+ const std::string buffer = load_data("sint32/data-max");
protozero::pbf_reader item(buffer);
@@ -44,7 +44,7 @@ TEST_CASE("read sint32 field") {
}
SECTION("min") {
- std::string buffer = load_data("sint32/data-min");
+ const std::string buffer = load_data("sint32/data-min");
protozero::pbf_reader item(buffer);
@@ -54,9 +54,9 @@ TEST_CASE("read sint32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("sint32/data-min");
+ const std::string buffer = load_data("sint32/data-min");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_sint32(), protozero::end_of_buffer_exception);
diff --git a/test/t/sint64/test_cases.cpp b/test/t/sint64/test_cases.cpp
index 8f6eaf4..2dec5b1 100644
--- a/test/t/sint64/test_cases.cpp
+++ b/test/t/sint64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read sint64 field") {
SECTION("zero") {
- std::string buffer = load_data("sint64/data-zero");
+ const std::string buffer = load_data("sint64/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read sint64 field") {
}
SECTION("positive") {
- std::string buffer = load_data("sint64/data-pos");
+ const std::string buffer = load_data("sint64/data-pos");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read sint64 field") {
}
SECTION("negative") {
- std::string buffer = load_data("sint64/data-neg");
+ const std::string buffer = load_data("sint64/data-neg");
protozero::pbf_reader item(buffer);
@@ -34,7 +34,7 @@ TEST_CASE("read sint64 field") {
}
SECTION("max") {
- std::string buffer = load_data("sint64/data-max");
+ const std::string buffer = load_data("sint64/data-max");
protozero::pbf_reader item(buffer);
@@ -44,7 +44,7 @@ TEST_CASE("read sint64 field") {
}
SECTION("min") {
- std::string buffer = load_data("sint64/data-min");
+ const std::string buffer = load_data("sint64/data-min");
protozero::pbf_reader item(buffer);
@@ -54,9 +54,9 @@ TEST_CASE("read sint64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("sint64/data-min");
+ const std::string buffer = load_data("sint64/data-min");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_sint64(), protozero::end_of_buffer_exception);
diff --git a/test/t/skip/test_cases.cpp b/test/t/skip/test_cases.cpp
index 14bd10f..fb4ee34 100644
--- a/test/t/skip/test_cases.cpp
+++ b/test/t/skip/test_cases.cpp
@@ -12,7 +12,7 @@ TEST_CASE("skip") {
// find . -name data\*pbf -not -empty | sed -e 's/^.\/\(.*\).pbf/"\1",/'
// and then remove everything manually that contains more than one
// field.
- std::vector<std::string> filenames = {
+ const std::vector<std::string> filenames = {
"bool/data-also-true",
"bool/data-false",
"bool/data-still-true",
@@ -99,7 +99,7 @@ TEST_CASE("skip") {
};
for (const auto& filename : filenames) {
- std::string buffer = load_data(filename);
+ const std::string buffer = load_data(filename);
protozero::pbf_reader item(buffer);
diff --git a/test/t/string/test_cases.cpp b/test/t/string/test_cases.cpp
index 5d840ff..4609581 100644
--- a/test/t/string/test_cases.cpp
+++ b/test/t/string/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read string field") {
SECTION("empty") {
- std::string buffer = load_data("string/data-empty");
+ const std::string buffer = load_data("string/data-empty");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read string field") {
}
SECTION("one") {
- std::string buffer = load_data("string/data-one");
+ const std::string buffer = load_data("string/data-one");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read string field") {
}
SECTION("string") {
- std::string buffer = load_data("string/data-string");
+ const std::string buffer = load_data("string/data-string");
protozero::pbf_reader item(buffer);
@@ -34,9 +34,9 @@ TEST_CASE("read string field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("string/data-string");
+ const std::string buffer = load_data("string/data-string");
- for (size_t i=1; i < buffer.size(); ++i) {
+ for (std::string::size_type i = 1; i < buffer.size(); ++i) {
protozero::pbf_reader item(buffer.data(), i);
REQUIRE(item.next());
REQUIRE_THROWS_AS(item.get_string(), protozero::end_of_buffer_exception);
@@ -44,7 +44,7 @@ TEST_CASE("read string field") {
}
SECTION("check assert on fixed int access") {
- std::string buffer = load_data("string/data-string");
+ const std::string buffer = load_data("string/data-string");
protozero::pbf_reader item(buffer);
diff --git a/test/t/uint32/test_cases.cpp b/test/t/uint32/test_cases.cpp
index deb0a5b..dcd525f 100644
--- a/test/t/uint32/test_cases.cpp
+++ b/test/t/uint32/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read uint32 field") {
SECTION("zero") {
- std::string buffer = load_data("uint32/data-zero");
+ const std::string buffer = load_data("uint32/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read uint32 field") {
}
SECTION("positive") {
- std::string buffer = load_data("uint32/data-pos");
+ const std::string buffer = load_data("uint32/data-pos");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read uint32 field") {
}
SECTION("max") {
- std::string buffer = load_data("uint32/data-max");
+ const std::string buffer = load_data("uint32/data-max");
protozero::pbf_reader item(buffer);
@@ -34,9 +34,9 @@ TEST_CASE("read uint32 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("uint32/data-max");
+ const std::string buffer = load_data("uint32/data-max");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_uint32(), protozero::end_of_buffer_exception);
diff --git a/test/t/uint64/test_cases.cpp b/test/t/uint64/test_cases.cpp
index 4d7c6f2..95a9168 100644
--- a/test/t/uint64/test_cases.cpp
+++ b/test/t/uint64/test_cases.cpp
@@ -4,7 +4,7 @@
TEST_CASE("read uint64 field") {
SECTION("zero") {
- std::string buffer = load_data("uint64/data-zero");
+ const std::string buffer = load_data("uint64/data-zero");
protozero::pbf_reader item(buffer);
@@ -14,7 +14,7 @@ TEST_CASE("read uint64 field") {
}
SECTION("positive") {
- std::string buffer = load_data("uint64/data-pos");
+ const std::string buffer = load_data("uint64/data-pos");
protozero::pbf_reader item(buffer);
@@ -24,7 +24,7 @@ TEST_CASE("read uint64 field") {
}
SECTION("max") {
- std::string buffer = load_data("uint64/data-max");
+ const std::string buffer = load_data("uint64/data-max");
protozero::pbf_reader item(buffer);
@@ -34,9 +34,9 @@ TEST_CASE("read uint64 field") {
}
SECTION("end_of_buffer") {
- std::string buffer = load_data("uint64/data-max");
+ const std::string buffer = load_data("uint64/data-max");
- for (size_t i=1; i < buffer.size(); ++i) {
+ 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_uint64(), protozero::end_of_buffer_exception);
diff --git a/test/t/vector_tile/test_cases.cpp b/test/t/vector_tile/test_cases.cpp
index 6c18c2e..314aeb7 100644
--- a/test/t/vector_tile/test_cases.cpp
+++ b/test/t/vector_tile/test_cases.cpp
@@ -7,7 +7,7 @@
// Input data.vector is encoded according to
// https://github.com/mapbox/mapnik-vector-tile/blob/master/proto/vector_tile.proto
-static std::vector<std::string> expected_layer_names = {
+static const std::vector<std::string> expected_layer_names = {
"landuse", "waterway", "water", "aeroway", "barrier_line", "building",
"landuse_overlay", "tunnel", "road", "bridge", "admin",
"country_label_line", "country_label", "marine_label", "state_label",
@@ -29,7 +29,7 @@ std::string get_name(protozero::pbf_reader layer) { // copy!
TEST_CASE("reading vector tiles") {
SECTION("iterate over message using next()") {
- std::string buffer = load_data("vector_tile/data.vector");
+ const std::string buffer = load_data("vector_tile/data.vector");
protozero::pbf_reader item(buffer);
@@ -55,7 +55,7 @@ TEST_CASE("reading vector tiles") {
}
SECTION("iterate over message using next(type)") {
- std::string buffer = load_data("vector_tile/data.vector");
+ const std::string buffer = load_data("vector_tile/data.vector");
protozero::pbf_reader item(buffer);
@@ -71,7 +71,7 @@ TEST_CASE("reading vector tiles") {
}
SECTION("iterate over features in road layer") {
- std::string buffer = load_data("vector_tile/data.vector");
+ const std::string buffer = load_data("vector_tile/data.vector");
protozero::pbf_reader item(buffer);
diff --git a/test/tests.cpp b/test/tests.cpp
index 378e07b..cec22a4 100644
--- a/test/tests.cpp
+++ b/test/tests.cpp
@@ -11,7 +11,7 @@ std::string load_data(const std::string& filename) {
fullname += filename;
fullname += ".pbf";
- std::ifstream stream(fullname.c_str(), std::ios_base::in|std::ios_base::binary);
+ std::ifstream stream(fullname, std::ios_base::in|std::ios_base::binary);
if (!stream.is_open())
{
throw std::runtime_error("could not open: '" + filename + "'");
diff --git a/tutorial.md b/tutorial.md
index e5de974..d5273ee 100644
--- a/tutorial.md
+++ b/tutorial.md
@@ -27,8 +27,8 @@ Keep the `protozero` directory and include the files in the form
#include <protozero/FILENAME.hpp>
-You always need `byteswap.hpp`, `pbf_types.hpp`, `varint.hpp`, and
-`exception.hpp`. For reading you need `pbf_reader.hpp` and probably
+You always need `byteswap.hpp`, `config.hpp`, `pbf_types.hpp`, `varint.hpp`,
+and `exception.hpp`. For reading you need `pbf_reader.hpp` and probably
`pbf_message.hpp`, for writing you need `pbf_writer.hpp` and probably
`pbf_builder.hpp`. You only need `version.hpp` if you want access to the macros
defining the library version.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/protozero.git
More information about the Pkg-grass-devel
mailing list