Skip to content

Commit

Permalink
Hook up the edition2023 cases to Rust conformance test.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 594235463
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 28, 2023
1 parent 442e079 commit 0b23719
Show file tree
Hide file tree
Showing 6 changed files with 709 additions and 21 deletions.
51 changes: 34 additions & 17 deletions conformance/conformance_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use kernel::Optional::{Set, Unset};

use std::io::{self, ErrorKind, Read, Write};
use test_messages_proto2::protobuf_test_messages::proto2::TestAllTypesProto2;
use test_messages_proto2_editions_proto::protobuf_test_messages::editions::proto2::TestAllTypesProto2 as EditionsTestAllTypesProto2;
use test_messages_proto3::protobuf_test_messages::proto3::TestAllTypesProto3;
use test_messages_proto3_editions_proto::protobuf_test_messages::editions::proto3::TestAllTypesProto3 as EditionsTestAllTypesProto3;

/// Returns Some(i32) if a binary read can succeed from stdin.
/// Returns None if we have reached an EOF.
Expand Down Expand Up @@ -58,11 +60,6 @@ fn write_response_to_stdout(resp: &ConformanceResponse) {
fn do_test(req: &ConformanceRequest) -> ConformanceResponse {
let mut resp = ConformanceResponse::new();
let message_type = req.message_type();
let is_proto2 = match message_type.as_bytes() {
b"protobuf_test_messages.proto2.TestAllTypesProto2" => true,
b"protobuf_test_messages.proto3.TestAllTypesProto3" => false,
_ => panic!("unexpected msg type {message_type}"),
};

// Enums aren't supported yet (and not in scope for v0.6) so we can't perform
// this check yet. Note that this causes Rust to fail every test case that asks
Expand All @@ -79,20 +76,40 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse {
Set(bytes) => bytes,
};

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 = match message_type.as_bytes() {
b"protobuf_test_messages.proto2.TestAllTypesProto2" => {
let mut proto = TestAllTypesProto2::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
}
proto.serialize()
}
proto.serialize()
} else {
let mut proto = TestAllTypesProto3::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
b"protobuf_test_messages.proto3.TestAllTypesProto3" => {
let mut proto = TestAllTypesProto3::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
}
proto.serialize()
}
b"protobuf_test_messages.editions.proto2.TestAllTypesProto2" => {
let mut proto = EditionsTestAllTypesProto2::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
}
proto.serialize()
}
proto.serialize()
b"protobuf_test_messages.editions.proto3.TestAllTypesProto3" => {
let mut proto = EditionsTestAllTypesProto3::new();
if let Err(_) = proto.deserialize(bytes) {
resp.parse_error_mut().set("failed to parse bytes");
return resp;
}
proto.serialize()
}
_ => panic!("unexpected msg type {message_type}"),
};

resp.protobuf_payload_mut().set(serialized);
Expand Down
Loading

0 comments on commit 0b23719

Please sign in to comment.