Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package impl_test |
| 6 | |
| 7 | import ( |
| 8 | "io" |
| 9 | "reflect" |
Joe Tsai | 32e8a52 | 2019-07-02 10:51:24 -0700 | [diff] [blame] | 10 | "sync" |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 11 | "testing" |
| 12 | |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 13 | "github.com/google/go-cmp/cmp" |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 14 | "google.golang.org/protobuf/encoding/prototext" |
| 15 | "google.golang.org/protobuf/internal/impl" |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 16 | "google.golang.org/protobuf/reflect/protodesc" |
Joe Tsai | 32e8a52 | 2019-07-02 10:51:24 -0700 | [diff] [blame] | 17 | "google.golang.org/protobuf/reflect/protoreflect" |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 18 | "google.golang.org/protobuf/runtime/protoiface" |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 19 | "google.golang.org/protobuf/testing/protocmp" |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 20 | |
| 21 | "google.golang.org/protobuf/types/descriptorpb" |
| 22 | ) |
| 23 | |
| 24 | type AberrantMessage struct { |
| 25 | OptionalBool *bool `protobuf:"varint,1,opt,name=opt_bool,def=1"` |
| 26 | OptionalInt32 *int32 `protobuf:"varint,2,opt,name=opt_int32,def=-12345"` |
| 27 | OptionalSint32 *int32 `protobuf:"zigzag32,3,opt,name=opt_sint32,def=-3200"` |
| 28 | OptionalUint32 *uint32 `protobuf:"varint,4,opt,name=opt_uint32,def=3200"` |
| 29 | OptionalInt64 *int64 `protobuf:"varint,5,opt,name=opt_int64,def=-123456789"` |
| 30 | OptionalSint64 *int64 `protobuf:"zigzag64,6,opt,name=opt_sint64,def=-6400"` |
| 31 | OptionalUint64 *uint64 `protobuf:"varint,7,opt,name=opt_uint64,def=6400"` |
| 32 | OptionalFixed32 *uint32 `protobuf:"fixed32,8,opt,name=opt_fixed32,def=320000"` |
| 33 | OptionalSfixed32 *int32 `protobuf:"fixed32,9,opt,name=opt_sfixed32,def=-320000"` |
| 34 | OptionalFloat *float32 `protobuf:"fixed32,10,opt,name=opt_float,def=3.14159"` |
| 35 | OptionalFixed64 *uint64 `protobuf:"fixed64,11,opt,name=opt_fixed64,def=640000"` |
| 36 | OptionalSfixed64 *int64 `protobuf:"fixed64,12,opt,name=opt_sfixed64,def=-640000"` |
| 37 | OptionalDouble *float64 `protobuf:"fixed64,13,opt,name=opt_double,def=3.14159265359"` |
| 38 | OptionalString *string `protobuf:"bytes,14,opt,name=opt_string,def=hello, \"world!\"\n"` |
| 39 | OptionalBytes []byte `protobuf:"bytes,15,opt,name=opt_bytes,def=dead\\336\\255\\276\\357beef"` |
| 40 | OptionalEnum *AberrantEnum `protobuf:"varint,16,opt,name=opt_enum,enum=google.golang.org.example.AberrantEnum,def=0"` |
| 41 | OptionalMessage *AberrantMessage `protobuf:"bytes,17,opt,name=opt_message"` |
| 42 | |
| 43 | RepeatedBool []bool `protobuf:"varint,18,rep,packed,name=rep_bool"` |
| 44 | RepeatedInt32 []int32 `protobuf:"varint,19,rep,packed,name=rep_int32"` |
| 45 | RepeatedSint32 []int32 `protobuf:"zigzag32,20,rep,packed,name=rep_sint32"` |
| 46 | RepeatedUint32 []uint32 `protobuf:"varint,21,rep,packed,name=rep_uint32"` |
| 47 | RepeatedInt64 []int64 `protobuf:"varint,22,rep,packed,name=rep_int64"` |
| 48 | RepeatedSint64 []int64 `protobuf:"zigzag64,23,rep,packed,name=rep_sint64"` |
| 49 | RepeatedUint64 []uint64 `protobuf:"varint,24,rep,packed,name=rep_uint64"` |
| 50 | RepeatedFixed32 []uint32 `protobuf:"fixed32,25,rep,packed,name=rep_fixed32"` |
| 51 | RepeatedSfixed32 []int32 `protobuf:"fixed32,26,rep,packed,name=rep_sfixed32"` |
| 52 | RepeatedFloat []float32 `protobuf:"fixed32,27,rep,packed,name=rep_float"` |
| 53 | RepeatedFixed64 []uint64 `protobuf:"fixed64,28,rep,packed,name=rep_fixed64"` |
| 54 | RepeatedSfixed64 []int64 `protobuf:"fixed64,29,rep,packed,name=rep_sfixed64"` |
| 55 | RepeatedDouble []float64 `protobuf:"fixed64,30,rep,packed,name=rep_double"` |
| 56 | RepeatedString []string `protobuf:"bytes,31,rep,name=rep_string"` |
| 57 | RepeatedBytes [][]byte `protobuf:"bytes,32,rep,name=rep_bytes"` |
| 58 | RepeatedEnum []AberrantEnum `protobuf:"varint,33,rep,name=rep_enum,enum=google.golang.org.example.AberrantEnum"` |
| 59 | RepeatedMessage []*AberrantMessage `protobuf:"bytes,34,rep,name=rep_message"` |
| 60 | |
| 61 | MapStringBool map[string]bool `protobuf:"bytes,35,rep,name=map_string_bool" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` |
| 62 | MapStringInt32 map[string]int32 `protobuf:"bytes,36,rep,name=map_string_int32" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` |
| 63 | MapStringSint32 map[string]int32 `protobuf:"bytes,37,rep,name=map_string_sint32" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"zigzag32,2,opt,name=value"` |
| 64 | MapStringUint32 map[string]uint32 `protobuf:"bytes,38,rep,name=map_string_uint32" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` |
| 65 | MapStringInt64 map[string]int64 `protobuf:"bytes,39,rep,name=map_string_int64" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` |
| 66 | MapStringSint64 map[string]int64 `protobuf:"bytes,40,rep,name=map_string_sint64" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"zigzag64,2,opt,name=value"` |
| 67 | MapStringUint64 map[string]uint64 `protobuf:"bytes,41,rep,name=map_string_uint64" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` |
| 68 | MapStringFixed32 map[string]uint32 `protobuf:"bytes,42,rep,name=map_string_fixed32" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed32,2,opt,name=value"` |
| 69 | MapStringSfixed32 map[string]int32 `protobuf:"bytes,43,rep,name=map_string_sfixed32" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed32,2,opt,name=value"` |
| 70 | MapStringFloat map[string]float32 `protobuf:"bytes,44,rep,name=map_string_float" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed32,2,opt,name=value"` |
| 71 | MapStringFixed64 map[string]uint64 `protobuf:"bytes,45,rep,name=map_string_fixed64" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed64,2,opt,name=value"` |
| 72 | MapStringSfixed64 map[string]int64 `protobuf:"bytes,46,rep,name=map_string_sfixed64" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed64,2,opt,name=value"` |
| 73 | MapStringDouble map[string]float64 `protobuf:"bytes,47,rep,name=map_string_double" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed64,2,opt,name=value"` |
| 74 | MapStringString map[string]string `protobuf:"bytes,48,rep,name=map_string_string" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` |
| 75 | MapStringBytes map[string][]byte `protobuf:"bytes,49,rep,name=map_string_bytes" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` |
| 76 | MapStringEnum map[string]AberrantEnum `protobuf:"bytes,50,rep,name=map_string_enum" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=google.golang.org.example.AberrantEnum"` |
| 77 | MapStringMessage map[string]*AberrantMessage `protobuf:"bytes,51,rep,name=map_string_message" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` |
| 78 | |
| 79 | OneofUnion isOneofUnion `protobuf_oneof:"oneof_union"` |
| 80 | |
| 81 | Ignored io.Reader |
| 82 | } |
| 83 | |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 84 | func (m *AberrantMessage) ExtensionRangeArray() []protoiface.ExtensionRangeV1 { |
| 85 | return []protoiface.ExtensionRangeV1{{Start: 10, End: 100}} |
| 86 | } |
| 87 | |
| 88 | func (m *AberrantMessage) XXX_OneofWrappers() []interface{} { |
| 89 | return []interface{}{ |
| 90 | (*OneofBool)(nil), |
| 91 | (*OneofInt32)(nil), |
| 92 | (*OneofSint32)(nil), |
| 93 | (*OneofUint32)(nil), |
| 94 | (*OneofInt64)(nil), |
| 95 | (*OneofSint64)(nil), |
| 96 | (*OneofUint64)(nil), |
| 97 | (*OneofFixed32)(nil), |
| 98 | (*OneofSfixed32)(nil), |
| 99 | (*OneofFloat)(nil), |
| 100 | (*OneofFixed64)(nil), |
| 101 | (*OneofSfixed64)(nil), |
| 102 | (*OneofDouble)(nil), |
| 103 | (*OneofString)(nil), |
| 104 | (*OneofBytes)(nil), |
| 105 | (*OneofEnum)(nil), |
| 106 | (*OneofMessage)(nil), |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | type isOneofUnion interface{ isOneofUnion() } |
| 111 | |
| 112 | type OneofBool struct { |
| 113 | OneofBool bool `protobuf:"varint,52,opt,name=oneof_bool,oneof,def=1"` |
| 114 | } |
| 115 | type OneofInt32 struct { |
| 116 | OneofInt32 int32 `protobuf:"varint,53,opt,name=oneof_int32,oneof,def=-12345"` |
| 117 | } |
| 118 | type OneofSint32 struct { |
| 119 | OneofSint32 int32 `protobuf:"zigzag32,54,opt,name=oneof_sint32,oneof,def=-3200"` |
| 120 | } |
| 121 | type OneofUint32 struct { |
| 122 | OneofUint32 uint32 `protobuf:"varint,55,opt,name=oneof_uint32,oneof,def=3200"` |
| 123 | } |
| 124 | type OneofInt64 struct { |
| 125 | OneofInt64 int64 `protobuf:"varint,56,opt,name=oneof_int64,oneof,def=-123456789"` |
| 126 | } |
| 127 | type OneofSint64 struct { |
| 128 | OneofSint64 int64 `protobuf:"zigzag64,57,opt,name=oneof_sint64,oneof,def=-6400"` |
| 129 | } |
| 130 | type OneofUint64 struct { |
| 131 | OneofUint64 uint64 `protobuf:"varint,58,opt,name=oneof_uint64,oneof,def=6400"` |
| 132 | } |
| 133 | type OneofFixed32 struct { |
| 134 | OneofFixed32 uint32 `protobuf:"fixed32,59,opt,name=oneof_fixed32,oneof,def=320000"` |
| 135 | } |
| 136 | type OneofSfixed32 struct { |
| 137 | OneofSfixed32 int32 `protobuf:"fixed32,60,opt,name=oneof_sfixed32,oneof,def=-320000"` |
| 138 | } |
| 139 | type OneofFloat struct { |
| 140 | OneofFloat float32 `protobuf:"fixed32,61,opt,name=oneof_float,oneof,def=3.14159"` |
| 141 | } |
| 142 | type OneofFixed64 struct { |
| 143 | OneofFixed64 uint64 `protobuf:"fixed64,62,opt,name=oneof_fixed64,oneof,def=640000"` |
| 144 | } |
| 145 | type OneofSfixed64 struct { |
| 146 | OneofSfixed64 int64 `protobuf:"fixed64,63,opt,name=oneof_sfixed64,oneof,def=-640000"` |
| 147 | } |
| 148 | type OneofDouble struct { |
| 149 | OneofDouble float64 `protobuf:"fixed64,64,opt,name=oneof_double,oneof,def=3.14159265359"` |
| 150 | } |
| 151 | type OneofString struct { |
| 152 | OneofString string `protobuf:"bytes,65,opt,name=oneof_string,oneof,def=hello, \"world!\"\n"` |
| 153 | } |
| 154 | type OneofBytes struct { |
| 155 | OneofBytes []byte `protobuf:"bytes,66,opt,name=oneof_bytes,oneof,def=dead\\336\\255\\276\\357beef"` |
| 156 | } |
| 157 | type OneofEnum struct { |
| 158 | OneofEnum AberrantEnum `protobuf:"varint,67,opt,name=oneof_enum,enum=google.golang.org.example.AberrantEnum,oneof,def=0"` |
| 159 | } |
| 160 | type OneofMessage struct { |
| 161 | OneofMessage *AberrantMessage `protobuf:"bytes,68,opt,name=oneof_message,oneof"` |
| 162 | } |
| 163 | |
| 164 | func (OneofBool) isOneofUnion() {} |
| 165 | func (OneofInt32) isOneofUnion() {} |
| 166 | func (OneofSint32) isOneofUnion() {} |
| 167 | func (OneofUint32) isOneofUnion() {} |
| 168 | func (OneofInt64) isOneofUnion() {} |
| 169 | func (OneofSint64) isOneofUnion() {} |
| 170 | func (OneofUint64) isOneofUnion() {} |
| 171 | func (OneofFixed32) isOneofUnion() {} |
| 172 | func (OneofSfixed32) isOneofUnion() {} |
| 173 | func (OneofFloat) isOneofUnion() {} |
| 174 | func (OneofFixed64) isOneofUnion() {} |
| 175 | func (OneofSfixed64) isOneofUnion() {} |
| 176 | func (OneofDouble) isOneofUnion() {} |
| 177 | func (OneofString) isOneofUnion() {} |
| 178 | func (OneofBytes) isOneofUnion() {} |
| 179 | func (OneofEnum) isOneofUnion() {} |
| 180 | func (OneofMessage) isOneofUnion() {} |
| 181 | |
| 182 | type AberrantEnum int32 |
| 183 | |
Joe Tsai | bee6252 | 2019-09-05 17:25:15 -0700 | [diff] [blame] | 184 | func TestAberrantMessages(t *testing.T) { |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 185 | enumName := impl.AberrantDeriveFullName(reflect.TypeOf(AberrantEnum(0))) |
| 186 | messageName := impl.AberrantDeriveFullName(reflect.TypeOf(AberrantMessage{})) |
| 187 | |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 188 | want := new(descriptorpb.DescriptorProto) |
| 189 | if err := prototext.Unmarshal([]byte(` |
| 190 | name: "AberrantMessage" |
| 191 | field: [ |
| 192 | {name:"opt_bool" number:1 label:LABEL_OPTIONAL type:TYPE_BOOL default_value:"true"}, |
| 193 | {name:"opt_int32" number:2 label:LABEL_OPTIONAL type:TYPE_INT32 default_value:"-12345"}, |
| 194 | {name:"opt_sint32" number:3 label:LABEL_OPTIONAL type:TYPE_SINT32 default_value:"-3200"}, |
| 195 | {name:"opt_uint32" number:4 label:LABEL_OPTIONAL type:TYPE_UINT32 default_value:"3200"}, |
| 196 | {name:"opt_int64" number:5 label:LABEL_OPTIONAL type:TYPE_INT64 default_value:"-123456789"}, |
| 197 | {name:"opt_sint64" number:6 label:LABEL_OPTIONAL type:TYPE_SINT64 default_value:"-6400"}, |
| 198 | {name:"opt_uint64" number:7 label:LABEL_OPTIONAL type:TYPE_UINT64 default_value:"6400"}, |
| 199 | {name:"opt_fixed32" number:8 label:LABEL_OPTIONAL type:TYPE_FIXED32 default_value:"320000"}, |
| 200 | {name:"opt_sfixed32" number:9 label:LABEL_OPTIONAL type:TYPE_SFIXED32 default_value:"-320000"}, |
| 201 | {name:"opt_float" number:10 label:LABEL_OPTIONAL type:TYPE_FLOAT default_value:"3.14159"}, |
| 202 | {name:"opt_fixed64" number:11 label:LABEL_OPTIONAL type:TYPE_FIXED64 default_value:"640000"}, |
| 203 | {name:"opt_sfixed64" number:12 label:LABEL_OPTIONAL type:TYPE_SFIXED64 default_value:"-640000"}, |
| 204 | {name:"opt_double" number:13 label:LABEL_OPTIONAL type:TYPE_DOUBLE default_value:"3.14159265359"}, |
| 205 | {name:"opt_string" number:14 label:LABEL_OPTIONAL type:TYPE_STRING default_value:"hello, \"world!\"\n"}, |
| 206 | {name:"opt_bytes" number:15 label:LABEL_OPTIONAL type:TYPE_BYTES default_value:"dead\\336\\255\\276\\357beef"}, |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 207 | {name:"opt_enum" number:16 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:".`+enumName+`" default_value:"UNKNOWN_0"}, |
| 208 | {name:"opt_message" number:17 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:".`+messageName+`"}, |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 209 | |
| 210 | {name:"rep_bool" number:18 label:LABEL_REPEATED type:TYPE_BOOL options:{packed:true}}, |
| 211 | {name:"rep_int32" number:19 label:LABEL_REPEATED type:TYPE_INT32 options:{packed:true}}, |
| 212 | {name:"rep_sint32" number:20 label:LABEL_REPEATED type:TYPE_SINT32 options:{packed:true}}, |
| 213 | {name:"rep_uint32" number:21 label:LABEL_REPEATED type:TYPE_UINT32 options:{packed:true}}, |
| 214 | {name:"rep_int64" number:22 label:LABEL_REPEATED type:TYPE_INT64 options:{packed:true}}, |
| 215 | {name:"rep_sint64" number:23 label:LABEL_REPEATED type:TYPE_SINT64 options:{packed:true}}, |
| 216 | {name:"rep_uint64" number:24 label:LABEL_REPEATED type:TYPE_UINT64 options:{packed:true}}, |
| 217 | {name:"rep_fixed32" number:25 label:LABEL_REPEATED type:TYPE_FIXED32 options:{packed:true}}, |
| 218 | {name:"rep_sfixed32" number:26 label:LABEL_REPEATED type:TYPE_SFIXED32 options:{packed:true}}, |
| 219 | {name:"rep_float" number:27 label:LABEL_REPEATED type:TYPE_FLOAT options:{packed:true}}, |
| 220 | {name:"rep_fixed64" number:28 label:LABEL_REPEATED type:TYPE_FIXED64 options:{packed:true}}, |
| 221 | {name:"rep_sfixed64" number:29 label:LABEL_REPEATED type:TYPE_SFIXED64 options:{packed:true}}, |
| 222 | {name:"rep_double" number:30 label:LABEL_REPEATED type:TYPE_DOUBLE options:{packed:true}}, |
| 223 | {name:"rep_string" number:31 label:LABEL_REPEATED type:TYPE_STRING}, |
| 224 | {name:"rep_bytes" number:32 label:LABEL_REPEATED type:TYPE_BYTES}, |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 225 | {name:"rep_enum" number:33 label:LABEL_REPEATED type:TYPE_ENUM type_name:".`+enumName+`"}, |
| 226 | {name:"rep_message" number:34 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`"}, |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 227 | |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 228 | {name:"map_string_bool" number:35 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringBoolEntry"}, |
| 229 | {name:"map_string_int32" number:36 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringInt32Entry"}, |
| 230 | {name:"map_string_sint32" number:37 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringSint32Entry"}, |
| 231 | {name:"map_string_uint32" number:38 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringUint32Entry"}, |
| 232 | {name:"map_string_int64" number:39 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringInt64Entry"}, |
| 233 | {name:"map_string_sint64" number:40 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringSint64Entry"}, |
| 234 | {name:"map_string_uint64" number:41 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringUint64Entry"}, |
| 235 | {name:"map_string_fixed32" number:42 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringFixed32Entry"}, |
| 236 | {name:"map_string_sfixed32" number:43 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringSfixed32Entry"}, |
| 237 | {name:"map_string_float" number:44 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringFloatEntry"}, |
| 238 | {name:"map_string_fixed64" number:45 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringFixed64Entry"}, |
| 239 | {name:"map_string_sfixed64" number:46 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringSfixed64Entry"}, |
| 240 | {name:"map_string_double" number:47 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringDoubleEntry"}, |
| 241 | {name:"map_string_string" number:48 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringStringEntry"}, |
| 242 | {name:"map_string_bytes" number:49 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringBytesEntry"}, |
| 243 | {name:"map_string_enum" number:50 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringEnumEntry"}, |
| 244 | {name:"map_string_message" number:51 label:LABEL_REPEATED type:TYPE_MESSAGE type_name:".`+messageName+`.MapStringMessageEntry"}, |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 245 | |
| 246 | {name:"oneof_bool" number:52 label:LABEL_OPTIONAL type:TYPE_BOOL oneof_index:0 default_value:"true"}, |
| 247 | {name:"oneof_int32" number:53 label:LABEL_OPTIONAL type:TYPE_INT32 oneof_index:0 default_value:"-12345"}, |
| 248 | {name:"oneof_sint32" number:54 label:LABEL_OPTIONAL type:TYPE_SINT32 oneof_index:0 default_value:"-3200"}, |
| 249 | {name:"oneof_uint32" number:55 label:LABEL_OPTIONAL type:TYPE_UINT32 oneof_index:0 default_value:"3200"}, |
| 250 | {name:"oneof_int64" number:56 label:LABEL_OPTIONAL type:TYPE_INT64 oneof_index:0 default_value:"-123456789"}, |
| 251 | {name:"oneof_sint64" number:57 label:LABEL_OPTIONAL type:TYPE_SINT64 oneof_index:0 default_value:"-6400"}, |
| 252 | {name:"oneof_uint64" number:58 label:LABEL_OPTIONAL type:TYPE_UINT64 oneof_index:0 default_value:"6400"}, |
| 253 | {name:"oneof_fixed32" number:59 label:LABEL_OPTIONAL type:TYPE_FIXED32 oneof_index:0 default_value:"320000"}, |
| 254 | {name:"oneof_sfixed32" number:60 label:LABEL_OPTIONAL type:TYPE_SFIXED32 oneof_index:0 default_value:"-320000"}, |
| 255 | {name:"oneof_float" number:61 label:LABEL_OPTIONAL type:TYPE_FLOAT oneof_index:0 default_value:"3.14159"}, |
| 256 | {name:"oneof_fixed64" number:62 label:LABEL_OPTIONAL type:TYPE_FIXED64 oneof_index:0 default_value:"640000"}, |
| 257 | {name:"oneof_sfixed64" number:63 label:LABEL_OPTIONAL type:TYPE_SFIXED64 oneof_index:0 default_value:"-640000"}, |
| 258 | {name:"oneof_double" number:64 label:LABEL_OPTIONAL type:TYPE_DOUBLE oneof_index:0 default_value:"3.14159265359"}, |
| 259 | {name:"oneof_string" number:65 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:0 default_value:"hello, \"world!\"\n"}, |
| 260 | {name:"oneof_bytes" number:66 label:LABEL_OPTIONAL type:TYPE_BYTES oneof_index:0 default_value:"dead\\336\\255\\276\\357beef"}, |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 261 | {name:"oneof_enum" number:67 label:LABEL_OPTIONAL type:TYPE_ENUM oneof_index:0 type_name:".`+enumName+`" default_value:"UNKNOWN_0"}, |
| 262 | {name:"oneof_message" number:68 label:LABEL_OPTIONAL type:TYPE_MESSAGE oneof_index:0 type_name:".`+messageName+`"} |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 263 | ] |
| 264 | oneof_decl: [{name:"oneof_union"}] |
| 265 | extension_range: [{start:10 end:101}] |
| 266 | nested_type: [ |
| 267 | {name:"MapStringBoolEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_BOOL}] options:{map_entry:true}}, |
| 268 | {name:"MapStringInt32Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_INT32}] options:{map_entry:true}}, |
| 269 | {name:"MapStringSint32Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_SINT32}] options:{map_entry:true}}, |
| 270 | {name:"MapStringUint32Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_UINT32}] options:{map_entry:true}}, |
| 271 | {name:"MapStringInt64Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_INT64}] options:{map_entry:true}}, |
| 272 | {name:"MapStringSint64Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_SINT64}] options:{map_entry:true}}, |
| 273 | {name:"MapStringUint64Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_UINT64}] options:{map_entry:true}}, |
| 274 | {name:"MapStringFixed32Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_FIXED32}] options:{map_entry:true}}, |
| 275 | {name:"MapStringSfixed32Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_SFIXED32}] options:{map_entry:true}}, |
| 276 | {name:"MapStringFloatEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_FLOAT}] options:{map_entry:true}}, |
| 277 | {name:"MapStringFixed64Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_FIXED64}] options:{map_entry:true}}, |
| 278 | {name:"MapStringSfixed64Entry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_SFIXED64}] options:{map_entry:true}}, |
| 279 | {name:"MapStringDoubleEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_DOUBLE}] options:{map_entry:true}}, |
| 280 | {name:"MapStringStringEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_STRING}] options:{map_entry:true}}, |
| 281 | {name:"MapStringBytesEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_BYTES}] options:{map_entry:true}}, |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 282 | {name:"MapStringEnumEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:".`+enumName+`"}] options:{map_entry:true}}, |
| 283 | {name:"MapStringMessageEntry" field:[{name:"key" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, {name:"value" number:2 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:".`+messageName+`"}] options:{map_entry:true}} |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 284 | ] |
| 285 | `), want); err != nil { |
| 286 | t.Fatalf("prototext.Unmarshal() error: %v", err) |
| 287 | } |
| 288 | |
| 289 | md := impl.LegacyLoadMessageDesc(reflect.TypeOf(&AberrantMessage{})) |
| 290 | got := protodesc.ToDescriptorProto(md) |
Joe Tsai | 55f1825 | 2020-01-11 00:25:01 -0800 | [diff] [blame] | 291 | if diff := cmp.Diff(want, got, protocmp.Transform()); diff != "" { |
| 292 | t.Errorf("mismatching descriptor (-want +got):\n%s", diff) |
Joe Tsai | 851185d | 2019-07-01 13:45:52 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
Joe Tsai | 32e8a52 | 2019-07-02 10:51:24 -0700 | [diff] [blame] | 295 | |
| 296 | type AberrantMessage1 struct { |
| 297 | M *AberrantMessage2 `protobuf:"bytes,1,opt,name=message"` |
| 298 | } |
| 299 | |
| 300 | type AberrantMessage2 struct { |
| 301 | M *AberrantMessage1 `protobuf:"bytes,1,opt,name=message"` |
| 302 | } |
| 303 | |
| 304 | func TestAberrantRace(t *testing.T) { |
| 305 | var gotMD1, wantMD1, gotMD2, wantMD2 protoreflect.MessageDescriptor |
| 306 | |
| 307 | var wg sync.WaitGroup |
| 308 | wg.Add(2) |
| 309 | go func() { |
| 310 | defer wg.Done() |
| 311 | md := impl.LegacyLoadMessageDesc(reflect.TypeOf(&AberrantMessage1{})) |
| 312 | wantMD2 = md.Fields().Get(0).Message() |
| 313 | gotMD2 = wantMD2.Fields().Get(0).Message().Fields().Get(0).Message() |
| 314 | }() |
| 315 | go func() { |
| 316 | defer wg.Done() |
| 317 | md := impl.LegacyLoadMessageDesc(reflect.TypeOf(&AberrantMessage2{})) |
| 318 | wantMD1 = md.Fields().Get(0).Message() |
| 319 | gotMD1 = wantMD1.Fields().Get(0).Message().Fields().Get(0).Message() |
| 320 | }() |
| 321 | wg.Wait() |
| 322 | |
| 323 | if gotMD1 != wantMD1 || gotMD2 != wantMD2 { |
| 324 | t.Errorf("mismatching exact message descriptors") |
| 325 | } |
| 326 | } |
Joe Tsai | bee6252 | 2019-09-05 17:25:15 -0700 | [diff] [blame] | 327 | |
| 328 | func TestAberrantExtensions(t *testing.T) { |
| 329 | tests := []struct { |
| 330 | in *impl.ExtensionInfo |
| 331 | wantName protoreflect.FullName |
| 332 | wantNumber protoreflect.FieldNumber |
| 333 | wantPlaceholder bool |
| 334 | }{{ |
| 335 | in: &impl.ExtensionInfo{Field: 500}, |
| 336 | wantNumber: 500, |
| 337 | wantPlaceholder: true, |
| 338 | }, { |
| 339 | in: &impl.ExtensionInfo{Name: "foo.bar.baz"}, |
| 340 | wantName: "foo.bar.baz", |
| 341 | wantPlaceholder: true, |
| 342 | }} |
| 343 | |
| 344 | for _, tt := range tests { |
| 345 | t.Run("", func(t *testing.T) { |
| 346 | xtd := tt.in.TypeDescriptor() |
| 347 | switch { |
| 348 | case xtd.FullName() != tt.wantName: |
| 349 | t.Errorf("FullName() = %v, want %v", xtd.FullName(), tt.wantName) |
| 350 | case xtd.Number() != tt.wantNumber: |
| 351 | t.Errorf("Number() = %v, want %v", xtd.Number(), tt.wantNumber) |
| 352 | case xtd.IsPlaceholder() != tt.wantPlaceholder: |
| 353 | t.Errorf("IsPlaceholder() = %v, want %v", xtd.IsPlaceholder(), tt.wantPlaceholder) |
| 354 | } |
| 355 | }) |
| 356 | } |
| 357 | } |