legacy_aberrant_test.go 24 KB

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