Skip to content

Commit

Permalink
Enable Rust conformance test on proto3 message.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 594051490
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 27, 2023
1 parent 2f7b283 commit 7f2b02c
Show file tree
Hide file tree
Showing 5 changed files with 661 additions and 9 deletions.
24 changes: 15 additions & 9 deletions conformance/conformance_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use kernel::Optional::{Set, Unset};

use std::io::{self, ErrorKind, Read, Write};
use test_messages_proto2::protobuf_test_messages::proto2::TestAllTypesProto2;
use test_messages_proto3::protobuf_test_messages::proto3::TestAllTypesProto3;

/// Returns Some(i32) if a binary read can succeed from stdin.
/// Returns None if we have reached an EOF.
Expand Down Expand Up @@ -64,8 +65,8 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse {
};

// Enums aren't supported yet (and not in scope for v0.6) so we can't perform
// this check yet.

// this check yet. Note that this causes Rust to fail every test case that asks
// for output that isn't wire format.
// if req.requested_output_format() != WireFormat.PROTOBUF {
// resp.skipped_mut().set("only wire format output implemented")
// }
Expand All @@ -78,19 +79,24 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse {
Set(bytes) => bytes,
};

if is_proto2 {
let serialized = if is_proto2 {
let mut proto = TestAllTypesProto2::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
}
let serialized = proto.serialize(); // Note: serialize() is infallible in Rust api.
resp.protobuf_payload_mut().set(serialized.as_ref());
return resp;
proto.serialize()
} else {
resp.skipped_mut().set("only proto2 supported");
return resp;
}
let mut proto = TestAllTypesProto3::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
}
proto.serialize()
};

resp.protobuf_payload_mut().set(serialized);
return resp;
}

fn main() {
Expand Down
Loading

0 comments on commit 7f2b02c

Please sign in to comment.