Added C++ test for the bug.

pull/13171/head
Joshua Haberman 3 years ago
parent 032400a03e
commit 31f7e2a261
  1. 35
      tests/test.proto
  2. 13
      tests/test_generated_code.cc

@ -11,3 +11,38 @@ message MessageName {
optional int32 field1 = 1; optional int32 field1 = 1;
optional int32 field2 = 2; optional int32 field2 = 2;
} }
message HelloRequest {
optional uint32 id = 1;
optional uint32 random_name_a0 = 2;
optional uint32 random_name_a1 = 3;
optional uint32 random_name_a2 = 4;
optional uint32 random_name_a3 = 5;
optional uint32 random_name_a4 = 6;
optional uint32 random_name_a5 = 7;
optional uint32 random_name_a6 = 8;
optional uint32 random_name_a7 = 9;
optional uint32 random_name_a8 = 10;
optional uint32 random_name_a9 = 11;
optional uint32 random_name_b0 = 12;
optional uint32 random_name_b1 = 13;
optional uint32 random_name_b2 = 14;
optional uint32 random_name_b3 = 15;
optional uint32 random_name_b4 = 16;
optional uint32 random_name_b5 = 17;
optional uint32 random_name_b6 = 18;
optional uint32 random_name_b7 = 19;
optional uint32 random_name_b8 = 20;
optional uint32 random_name_b9 = 21;
optional uint32 random_name_c0 = 22;
optional uint32 random_name_c1 = 23;
optional uint32 random_name_c2 = 24;
optional uint32 random_name_c3 = 25;
optional uint32 random_name_c4 = 26;
optional uint32 random_name_c5 = 27;
optional uint32 random_name_c6 = 28;
optional uint32 random_name_c7 = 29;
optional uint32 random_name_c8 = 30;
optional uint32 random_name_c9 = 31;
optional string version = 32;
}

@ -30,9 +30,10 @@
* upb/def.c and tests/conformance_upb.c, respectively). * upb/def.c and tests/conformance_upb.c, respectively).
*/ */
#include "gtest/gtest.h"
#include "src/google/protobuf/test_messages_proto3.upb.h" #include "src/google/protobuf/test_messages_proto3.upb.h"
#include "tests/test.upb.h" #include "tests/test.upb.h"
#include "gtest/gtest.h" #include "upb/upb.hpp"
#define MIN(x, y) ((x) < (y) ? (x) : (y)) #define MIN(x, y) ((x) < (y) ? (x) : (y))
@ -411,6 +412,16 @@ TEST(GeneratedCode, TestRepeated) {
upb_Arena_Free(arena); upb_Arena_Free(arena);
} }
TEST(GeneratedCode, Issue9440) {
upb::Arena arena;
upb_test_HelloRequest* msg = upb_test_HelloRequest_new(arena.ptr());
upb_test_HelloRequest_set_id(msg, 8);
EXPECT_EQ(8, upb_test_HelloRequest_id(msg));
char str[] = "1";
upb_test_HelloRequest_set_version(msg, upb_StringView{str, strlen(str)});
EXPECT_EQ(8, upb_test_HelloRequest_id(msg));
}
TEST(GeneratedCode, NullDecodeBuffer) { TEST(GeneratedCode, NullDecodeBuffer) {
upb_Arena* arena = upb_Arena_New(); upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto3_TestAllTypesProto3* msg = protobuf_test_messages_proto3_TestAllTypesProto3* msg =

Loading…
Cancel
Save