|
21 | 21 | #include "hpb/arena.h" |
22 | 22 | #include "hpb/backend/upb/interop.h" |
23 | 23 | #include "hpb/hpb.h" |
| 24 | +#include "hpb/options.h" |
24 | 25 | #include "hpb/ptr.h" |
25 | 26 | #include "hpb/requires.h" |
| 27 | +#include "hpb/status.h" |
26 | 28 |
|
27 | 29 | namespace { |
28 | 30 |
|
@@ -405,6 +407,30 @@ TEST(CppGeneratedCode, MessageMapStringKeyAndInt32Value) { |
405 | 407 | EXPECT_EQ(false, result_after_delete.ok()); |
406 | 408 | } |
407 | 409 |
|
| 410 | +TEST(CppGeneratedCode, HpbStatus) { |
| 411 | + TestModel model; |
| 412 | + model.set_str1("lightweight status"); |
| 413 | + hpb::Arena arena; |
| 414 | + absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(&model, arena); |
| 415 | + EXPECT_EQ(true, bytes.ok()); |
| 416 | + |
| 417 | + hpb::StatusOr<TestModel> parsed_model = ::hpb::Parse<TestModel>( |
| 418 | + bytes.value(), hpb::ParseOptionsWithEmptyRegistry()); |
| 419 | + EXPECT_EQ(true, parsed_model.ok()); |
| 420 | + EXPECT_EQ("lightweight status", parsed_model.value().str1()); |
| 421 | +} |
| 422 | + |
| 423 | +TEST(CppGeneratedCode, HpbStatusFail) { |
| 424 | + hpb::StatusOr<TestModel> status = ::hpb::Parse<TestModel>( |
| 425 | + "definitely not a proto", hpb::ParseOptionsWithEmptyRegistry()); |
| 426 | + EXPECT_EQ(false, status.ok()); |
| 427 | + EXPECT_EQ(status.error(), "Wire format was corrupt"); |
| 428 | + |
| 429 | + absl::StatusOr<TestModel> to_absl_status = status.ToAbslStatusOr(); |
| 430 | + EXPECT_EQ(false, to_absl_status.ok()); |
| 431 | + EXPECT_EQ(to_absl_status.status().message(), "Wire format was corrupt"); |
| 432 | +} |
| 433 | + |
408 | 434 | TEST(CppGeneratedCode, SerializeUsingArena) { |
409 | 435 | TestModel model; |
410 | 436 | model.set_str1("Hello World"); |
|
0 commit comments