diff options
Diffstat (limited to 'src/google/protobuf/arena_test_util.h')
-rw-r--r-- | src/google/protobuf/arena_test_util.h | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/google/protobuf/arena_test_util.h b/src/google/protobuf/arena_test_util.h index df56ece8..fdbaca06 100644 --- a/src/google/protobuf/arena_test_util.h +++ b/src/google/protobuf/arena_test_util.h @@ -33,6 +33,8 @@ #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/io/coded_stream.h> +#include <google/protobuf/io/zero_copy_stream_impl_lite.h> #include <google/protobuf/arena.h> namespace google { @@ -41,16 +43,23 @@ namespace protobuf { template <typename T, bool use_arena> void TestParseCorruptedString(const T& message) { int success_count = 0; - string s = message.SerializeAsString(); + std::string s; + { + // Map order is not deterministic. To make the test deterministic we want + // to serialize the proto deterministically. + io::StringOutputStream output(&s); + io::CodedOutputStream out(&output); + out.SetSerializationDeterministic(true); + message.SerializePartialToCodedStream(&out); + } const int kMaxIters = 900; const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters; const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2; for (int i = start; i < s.size(); i += stride) { for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) { s[i] ^= c; - google::protobuf::Arena arena; - T* message = - google::protobuf::Arena::CreateMessage<T>(use_arena ? &arena : nullptr); + Arena arena; + T* message = Arena::CreateMessage<T>(use_arena ? &arena : nullptr); if (message->ParseFromString(s)) { ++success_count; } @@ -86,6 +95,6 @@ class NoHeapChecker { } // namespace internal } // namespace protobuf - } // namespace google + #endif // GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ |