Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/check_decode/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
//
// Contract:
//
// check_decode --format <pxf|pxf-pb|pb|pb-render|pb-text|sbe|envelope> \
// --schema <fully.qualified.MessageType> \
// --proto <path-to-adversarial.proto> \
// --input <path> \
// check_decode --format <pxf|pxf-pb|pb|pb-render|pb-text|sbe|envelope>
// --schema <fully.qualified.MessageType>
// --proto <path-to-adversarial.proto>
// --input <path>
// [--limit NAME=VALUE ...]
//
// Exit 0 → input was accepted (decode succeeded)
Expand Down
6 changes: 3 additions & 3 deletions src/pxf/go_wire.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite.h>

namespace protowire::pxf {
Expand Down Expand Up @@ -199,9 +200,8 @@ void WriteMessage(const pb::Message& msg, pb::io::CodedOutputStream* out) {
r->ListFields(msg, &fields);
std::sort(fields.begin(), fields.end(), GoFieldLess);
for (const FieldDescriptor* fd : fields) WriteField(msg, fd, out);
std::string unknown;
r->GetUnknownFields(msg).SerializeToString(&unknown);
out->WriteString(unknown);
// Straight into the stream: no copy, and no result to drop (#158).
pb::internal::WireFormat::SerializeUnknownFields(r->GetUnknownFields(msg), out);
}

} // namespace
Expand Down
12 changes: 8 additions & 4 deletions src/pxf/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void WalkEnumsForFile(std::string_view path,
out->push_back(Violation{std::string(path),
std::string(v->full_name()),
std::string(v->name()),
ViolationKind::kEnumValue});
ViolationKind::kEnumValue,
/*detail=*/{}});
}
}
}
Expand All @@ -58,7 +59,8 @@ void WalkEnumsForMessage(std::string_view path,
out->push_back(Violation{std::string(path),
std::string(v->full_name()),
std::string(v->name()),
ViolationKind::kEnumValue});
ViolationKind::kEnumValue,
/*detail=*/{}});
}
}
}
Expand Down Expand Up @@ -241,7 +243,8 @@ void WalkMessages(std::string_view path, const pb::Descriptor* md, std::vector<V
out->push_back(Violation{std::string(path),
std::string(f->full_name()),
std::string(f->name()),
ViolationKind::kField});
ViolationKind::kField,
/*detail=*/{}});
}
// A field declared with no options shares the default instance and can
// carry no annotation. Most fields in a closure are like this, and this
Expand All @@ -263,7 +266,8 @@ void WalkMessages(std::string_view path, const pb::Descriptor* md, std::vector<V
out->push_back(Violation{std::string(path),
std::string(o->full_name()),
std::string(o->name()),
ViolationKind::kOneof});
ViolationKind::kOneof,
/*detail=*/{}});
}
}
for (int i = 0; i < md->nested_type_count(); ++i) {
Expand Down
10 changes: 5 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ add_executable(protowire_detail_test
detail_rfc3339_test.cc
detail_duration_test.cc)
target_link_libraries(protowire_detail_test PRIVATE
protowire_detail GTest::gtest GTest::gtest_main)
protowire_detail GTest::gtest_main)
gtest_discover_tests(protowire_detail_test)

if(TARGET protowire_pb AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/pb_test.cc)
add_executable(protowire_pb_test pb_test.cc pb_stream_test.cc pb_utf8_test.cc pb_values_table_test.cc)
target_link_libraries(protowire_pb_test PRIVATE
protowire_pb GTest::gtest GTest::gtest_main)
protowire_pb GTest::gtest_main)
target_compile_definitions(protowire_pb_test PRIVATE
TESTDATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../testdata")
gtest_discover_tests(protowire_pb_test)
Expand All @@ -28,7 +28,7 @@ endif()
if(TARGET protowire_envelope AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/envelope_test.cc)
add_executable(protowire_envelope_test envelope_test.cc)
target_link_libraries(protowire_envelope_test PRIVATE
protowire_envelope GTest::gtest GTest::gtest_main)
protowire_envelope GTest::gtest_main)
gtest_discover_tests(protowire_envelope_test)
endif()

Expand All @@ -52,7 +52,7 @@ if(TARGET protowire_pxf)
add_executable(protowire_pxf_test ${_pxf_test_srcs})
target_link_libraries(protowire_pxf_test PRIVATE
protowire_pxf protobuf::libprotoc
GTest::gtest GTest::gtest_main)
GTest::gtest_main)
target_compile_definitions(protowire_pxf_test PRIVATE
TESTDATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../testdata"
PROTO_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../proto"
Expand All @@ -74,7 +74,7 @@ if(TARGET protowire_sbe)
add_executable(protowire_sbe_test ${_sbe_test_srcs})
target_link_libraries(protowire_sbe_test PRIVATE
protowire_sbe protobuf::libprotoc
GTest::gtest GTest::gtest_main)
GTest::gtest_main)
target_compile_definitions(protowire_sbe_test PRIVATE
PROTO_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../proto"
WKT_PROTO_DIR="${Protobuf_INCLUDE_DIR}")
Expand Down
4 changes: 2 additions & 2 deletions test/pxf_any_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ payload {
ASSERT_TRUE(protowire::pxf::Unmarshal(*encoded, msg2.get(), uopts).ok());

std::string s1, s2;
msg1->SerializeToString(&s1);
msg2->SerializeToString(&s2);
ASSERT_TRUE(msg1->SerializeToString(&s1));
ASSERT_TRUE(msg2->SerializeToString(&s2));
EXPECT_EQ(s1, s2);
}

Expand Down
6 changes: 3 additions & 3 deletions test/pxf_carrier_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ std::string Other() {
struct FieldSpec {
std::string name;
pb::FieldDescriptorProto::Type type;
std::string carrier;
std::string bracket_default; // (pxf.default) at extension 1315
std::string carrier = {};
std::string bracket_default = {}; // (pxf.default) at extension 1315
bool bracket_required = false;
std::string type_name;
std::string type_name = {};
};

// Schema builds one message M in a pool of its own.
Expand Down
2 changes: 1 addition & 1 deletion test/pxf_corpus_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ std::string Bytes(const pbuf::Message& m) {
pbuf::io::StringOutputStream raw(&out);
pbuf::io::CodedOutputStream coded(&raw);
coded.SetSerializationDeterministic(true);
m.SerializeToCodedStream(&coded);
EXPECT_TRUE(m.SerializeToCodedStream(&coded));
return out;
}

Expand Down
4 changes: 2 additions & 2 deletions test/pxf_decode_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ TEST_F(PxfDecode, RoundTrip) {
auto msg2 = NewAllTypes();
ASSERT_TRUE(protowire::pxf::Unmarshal(*encoded, msg2.get()).ok());
std::string s1, s2;
msg->SerializeToString(&s1);
msg2->SerializeToString(&s2);
ASSERT_TRUE(msg->SerializeToString(&s1));
ASSERT_TRUE(msg2->SerializeToString(&s2));
EXPECT_EQ(s1, s2);
}

Expand Down
4 changes: 2 additions & 2 deletions test/pxf_full_roundtrip_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Trip RunFullPipeline(FullRoundTrip* f, const std::string& src) {
t.m1 = f->NewAllTypes();
EXPECT_TRUE(protowire::pxf::Unmarshal(src, t.m1.get()).ok());
// Force size cache (required before SerializeWithCachedSizes).
t.m1->ByteSizeLong();
(void)t.m1->ByteSizeLong();
SerializeDeterministic(*t.m1, &t.bin1);

t.m2 = f->NewAllTypes();
Expand All @@ -117,7 +117,7 @@ Trip RunFullPipeline(FullRoundTrip* f, const std::string& src) {

t.m3 = f->NewAllTypes();
EXPECT_TRUE(protowire::pxf::Unmarshal(t.text1, t.m3.get()).ok());
t.m3->ByteSizeLong();
(void)t.m3->ByteSizeLong(); // the size cache, as for m1
SerializeDeterministic(*t.m3, &t.bin3);

return t;
Expand Down
11 changes: 11 additions & 0 deletions test/pxf_go_parity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ TEST_F(GoParity, OneofMembersSerializeLast) {
EXPECT_EQ(copy->ShortDebugString(), msg->ShortDebugString());
}

// Unknown fields follow the known ones, byte for byte (#158: they used to go
// through an unchecked SerializeToString).
TEST_F(GoParity, UnknownFieldsSerializeAfterTheKnownOnes) {
auto msg = New("diff.v1.Leaf");
// number = 3, then field 99 (varint 5) and field 100 (bytes "zz"), unknown to Leaf.
const std::string wire("\x30\x03\x98\x06\x05\xa2\x06\x02zz", 10);
ASSERT_TRUE(msg->ParseFromString(wire));
ASSERT_EQ(msg->GetReflection()->GetUnknownFields(*msg).field_count(), 2);
EXPECT_EQ(pxf::SerializeGoOrder(*msg), wire);
}

TEST_F(GoParity, SecretHookTakesEveryForm) {
std::vector<std::pair<std::string, std::string>> got;
pxf::UnmarshalOptions opts;
Expand Down
4 changes: 3 additions & 1 deletion test/pxf_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,9 @@ TEST(RewriterKeyedComments, AnonCommentsSurviveEveryEdit) {
ASSERT_TRUE(pxf::Parse(got).ok()) << got;
++checked;
for (const std::string& k : keys) {
if (between) EXPECT_TRUE(Has(got, "// before " + k + "\n")) << got;
if (between) {
EXPECT_TRUE(Has(got, "// before " + k + "\n")) << got;
}
if (trail.empty() || k == gone) continue;
bool ok = false;
std::istringstream lines(got);
Expand Down
4 changes: 3 additions & 1 deletion test/sbe_header_bounds_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ TEST(SbeHeaderBounds, NewCodec) {
ADD_FAILURE() << "short header";
continue;
}
if (tc.block_size != 0) EXPECT_EQ(Le16(*data, 0), tc.block_size) << "blockLength";
if (tc.block_size != 0) {
EXPECT_EQ(Le16(*data, 0), tc.block_size) << "blockLength";
}
EXPECT_EQ(std::to_string(Le16(*data, 4)), schema_id) << "schemaId";
EXPECT_EQ(std::to_string(Le16(*data, 6)), version) << "version";

Expand Down
Loading