From 26d98ca94f2f049e8767b4a9a33d185a3d7ea0fd Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 24 Oct 2013 12:43:19 -0700 Subject: Merge from Google-internal development: - rewritten decoder; interpreted decoder is bytecode-based, JIT decoder no longer falls back to the interpreter. - C++ improvements: C++11-compatible iterators, upb::reffed_ptr for RAII refcounting, better upcast/downcast support. - removed the gross upb_value abstraction from public upb.h. --- tests/test_vs_proto2.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'tests/test_vs_proto2.cc') diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index bc6df46..d766b42 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -24,14 +25,15 @@ #include "upb/handlers.h" #include "upb/pb/decoder.h" #include "upb/pb/glue.h" -#include "upb/pb/varint.h" +#include "upb/pb/varint.int.h" #include "upb_test.h" void compare_metadata(const google::protobuf::Descriptor* d, const upb::MessageDef *upb_md) { ASSERT(d->field_count() == upb_md->field_count()); - for (upb::MessageDef::ConstIterator i(upb_md); !i.Done(); i.Next()) { - const upb::FieldDef* upb_f = i.field(); + for (upb::MessageDef::const_iterator i = upb_md->begin(); i != upb_md->end(); + ++i) { + const upb::FieldDef* upb_f = *i; const google::protobuf::FieldDescriptor *proto2_f = d->FindFieldByNumber(upb_f->number()); ASSERT(upb_f); @@ -65,6 +67,9 @@ void parse_and_compare(google::protobuf::Message *msg1, msg2->Clear(); bool ok = upb::PutStringToBytestream(decoder_sink, str, len); + if (!ok) { + fprintf(stderr, "error parsing: %s\n", pipeline.status().GetString()); + } ASSERT(ok); ASSERT(pipeline.status().ok()); @@ -76,12 +81,21 @@ void parse_and_compare(google::protobuf::Message *msg1, std::string str2; msg1->SerializeToString(&str1); msg2->SerializeToString(&str2); + + std::string text_str1; + std::string text_str2; + google::protobuf::TextFormat::PrintToString(*msg1, &text_str1); + google::protobuf::TextFormat::PrintToString(*msg2, &text_str2); + if (str1 != str2) { + fprintf(stderr, "str1: %s, str2: %s\n", + text_str1.c_str(), text_str2.c_str()); + } ASSERT(str1 == str2); ASSERT(std::string(str, len) == str2); } void test_zig_zag() { - for (uint64_t num = 5; num * 1.5 > num; num *= 1.5) { + for (uint64_t num = 5; num * 1.5 < UINT64_MAX; num *= 1.5) { ASSERT(upb_zzenc_64(num) == google::protobuf::internal::WireFormatLite::ZigZagEncode64(num)); if (num < UINT32_MAX) { -- cgit v1.2.3