/test/oneof3/combos/unmarshaler/onepb_test.go

https://github.com/gogo/protobuf · Go · 372 lines · 353 code · 13 blank · 6 comment · 110 complexity · 484211b75d2317ef09e85d4d13c08987 MD5 · raw file

  1. // Code generated by protoc-gen-gogo. DO NOT EDIT.
  2. // source: combos/unmarshaler/one.proto
  3. package one
  4. import (
  5. fmt "fmt"
  6. _ "github.com/gogo/protobuf/gogoproto"
  7. github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb"
  8. github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
  9. proto "github.com/gogo/protobuf/proto"
  10. go_parser "go/parser"
  11. math "math"
  12. math_rand "math/rand"
  13. testing "testing"
  14. time "time"
  15. )
  16. // Reference imports to suppress errors if they are not otherwise used.
  17. var _ = proto.Marshal
  18. var _ = fmt.Errorf
  19. var _ = math.Inf
  20. func TestSubbyProto(t *testing.T) {
  21. seed := time.Now().UnixNano()
  22. popr := math_rand.New(math_rand.NewSource(seed))
  23. p := NewPopulatedSubby(popr, false)
  24. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  25. if err != nil {
  26. t.Fatalf("seed = %d, err = %v", seed, err)
  27. }
  28. msg := &Subby{}
  29. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  30. t.Fatalf("seed = %d, err = %v", seed, err)
  31. }
  32. littlefuzz := make([]byte, len(dAtA))
  33. copy(littlefuzz, dAtA)
  34. for i := range dAtA {
  35. dAtA[i] = byte(popr.Intn(256))
  36. }
  37. if err := p.VerboseEqual(msg); err != nil {
  38. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  39. }
  40. if !p.Equal(msg) {
  41. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  42. }
  43. if len(littlefuzz) > 0 {
  44. fuzzamount := 100
  45. for i := 0; i < fuzzamount; i++ {
  46. littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
  47. littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
  48. }
  49. // shouldn't panic
  50. _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
  51. }
  52. }
  53. func TestSampleOneOfProto(t *testing.T) {
  54. seed := time.Now().UnixNano()
  55. popr := math_rand.New(math_rand.NewSource(seed))
  56. p := NewPopulatedSampleOneOf(popr, false)
  57. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  58. if err != nil {
  59. t.Fatalf("seed = %d, err = %v", seed, err)
  60. }
  61. msg := &SampleOneOf{}
  62. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  63. t.Fatalf("seed = %d, err = %v", seed, err)
  64. }
  65. littlefuzz := make([]byte, len(dAtA))
  66. copy(littlefuzz, dAtA)
  67. for i := range dAtA {
  68. dAtA[i] = byte(popr.Intn(256))
  69. }
  70. if err := p.VerboseEqual(msg); err != nil {
  71. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  72. }
  73. if !p.Equal(msg) {
  74. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  75. }
  76. if len(littlefuzz) > 0 {
  77. fuzzamount := 100
  78. for i := 0; i < fuzzamount; i++ {
  79. littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
  80. littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
  81. }
  82. // shouldn't panic
  83. _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
  84. }
  85. }
  86. func TestSubbyJSON(t *testing.T) {
  87. seed := time.Now().UnixNano()
  88. popr := math_rand.New(math_rand.NewSource(seed))
  89. p := NewPopulatedSubby(popr, true)
  90. marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
  91. jsondata, err := marshaler.MarshalToString(p)
  92. if err != nil {
  93. t.Fatalf("seed = %d, err = %v", seed, err)
  94. }
  95. msg := &Subby{}
  96. err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
  97. if err != nil {
  98. t.Fatalf("seed = %d, err = %v", seed, err)
  99. }
  100. if err := p.VerboseEqual(msg); err != nil {
  101. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  102. }
  103. if !p.Equal(msg) {
  104. t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
  105. }
  106. }
  107. func TestSampleOneOfJSON(t *testing.T) {
  108. seed := time.Now().UnixNano()
  109. popr := math_rand.New(math_rand.NewSource(seed))
  110. p := NewPopulatedSampleOneOf(popr, true)
  111. marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
  112. jsondata, err := marshaler.MarshalToString(p)
  113. if err != nil {
  114. t.Fatalf("seed = %d, err = %v", seed, err)
  115. }
  116. msg := &SampleOneOf{}
  117. err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
  118. if err != nil {
  119. t.Fatalf("seed = %d, err = %v", seed, err)
  120. }
  121. if err := p.VerboseEqual(msg); err != nil {
  122. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  123. }
  124. if !p.Equal(msg) {
  125. t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
  126. }
  127. }
  128. func TestSubbyProtoText(t *testing.T) {
  129. seed := time.Now().UnixNano()
  130. popr := math_rand.New(math_rand.NewSource(seed))
  131. p := NewPopulatedSubby(popr, true)
  132. dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
  133. msg := &Subby{}
  134. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  135. t.Fatalf("seed = %d, err = %v", seed, err)
  136. }
  137. if err := p.VerboseEqual(msg); err != nil {
  138. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  139. }
  140. if !p.Equal(msg) {
  141. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  142. }
  143. }
  144. func TestSubbyProtoCompactText(t *testing.T) {
  145. seed := time.Now().UnixNano()
  146. popr := math_rand.New(math_rand.NewSource(seed))
  147. p := NewPopulatedSubby(popr, true)
  148. dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
  149. msg := &Subby{}
  150. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  151. t.Fatalf("seed = %d, err = %v", seed, err)
  152. }
  153. if err := p.VerboseEqual(msg); err != nil {
  154. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  155. }
  156. if !p.Equal(msg) {
  157. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  158. }
  159. }
  160. func TestSampleOneOfProtoText(t *testing.T) {
  161. seed := time.Now().UnixNano()
  162. popr := math_rand.New(math_rand.NewSource(seed))
  163. p := NewPopulatedSampleOneOf(popr, true)
  164. dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
  165. msg := &SampleOneOf{}
  166. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  167. t.Fatalf("seed = %d, err = %v", seed, err)
  168. }
  169. if err := p.VerboseEqual(msg); err != nil {
  170. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  171. }
  172. if !p.Equal(msg) {
  173. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  174. }
  175. }
  176. func TestSampleOneOfProtoCompactText(t *testing.T) {
  177. seed := time.Now().UnixNano()
  178. popr := math_rand.New(math_rand.NewSource(seed))
  179. p := NewPopulatedSampleOneOf(popr, true)
  180. dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
  181. msg := &SampleOneOf{}
  182. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  183. t.Fatalf("seed = %d, err = %v", seed, err)
  184. }
  185. if err := p.VerboseEqual(msg); err != nil {
  186. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  187. }
  188. if !p.Equal(msg) {
  189. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  190. }
  191. }
  192. func TestSubbyCompare(t *testing.T) {
  193. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  194. p := NewPopulatedSubby(popr, false)
  195. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  196. if err != nil {
  197. panic(err)
  198. }
  199. msg := &Subby{}
  200. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  201. panic(err)
  202. }
  203. if c := p.Compare(msg); c != 0 {
  204. t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)
  205. }
  206. p2 := NewPopulatedSubby(popr, false)
  207. c := p.Compare(p2)
  208. c2 := p2.Compare(p)
  209. if c != (-1 * c2) {
  210. t.Errorf("p.Compare(p2) = %d", c)
  211. t.Errorf("p2.Compare(p) = %d", c2)
  212. t.Errorf("p = %#v", p)
  213. t.Errorf("p2 = %#v", p2)
  214. }
  215. }
  216. func TestSampleOneOfCompare(t *testing.T) {
  217. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  218. p := NewPopulatedSampleOneOf(popr, false)
  219. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  220. if err != nil {
  221. panic(err)
  222. }
  223. msg := &SampleOneOf{}
  224. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  225. panic(err)
  226. }
  227. if c := p.Compare(msg); c != 0 {
  228. t.Fatalf("%#v !Compare %#v, since %d", msg, p, c)
  229. }
  230. p2 := NewPopulatedSampleOneOf(popr, false)
  231. c := p.Compare(p2)
  232. c2 := p2.Compare(p)
  233. if c != (-1 * c2) {
  234. t.Errorf("p.Compare(p2) = %d", c)
  235. t.Errorf("p2.Compare(p) = %d", c2)
  236. t.Errorf("p = %#v", p)
  237. t.Errorf("p2 = %#v", p2)
  238. }
  239. }
  240. func TestOneDescription(t *testing.T) {
  241. OneDescription()
  242. }
  243. func TestSubbyVerboseEqual(t *testing.T) {
  244. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  245. p := NewPopulatedSubby(popr, false)
  246. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  247. if err != nil {
  248. panic(err)
  249. }
  250. msg := &Subby{}
  251. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  252. panic(err)
  253. }
  254. if err := p.VerboseEqual(msg); err != nil {
  255. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  256. }
  257. }
  258. func TestSampleOneOfVerboseEqual(t *testing.T) {
  259. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  260. p := NewPopulatedSampleOneOf(popr, false)
  261. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  262. if err != nil {
  263. panic(err)
  264. }
  265. msg := &SampleOneOf{}
  266. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  267. panic(err)
  268. }
  269. if err := p.VerboseEqual(msg); err != nil {
  270. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  271. }
  272. }
  273. func TestSubbyGoString(t *testing.T) {
  274. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  275. p := NewPopulatedSubby(popr, false)
  276. s1 := p.GoString()
  277. s2 := fmt.Sprintf("%#v", p)
  278. if s1 != s2 {
  279. t.Fatalf("GoString want %v got %v", s1, s2)
  280. }
  281. _, err := go_parser.ParseExpr(s1)
  282. if err != nil {
  283. t.Fatal(err)
  284. }
  285. }
  286. func TestSampleOneOfGoString(t *testing.T) {
  287. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  288. p := NewPopulatedSampleOneOf(popr, false)
  289. s1 := p.GoString()
  290. s2 := fmt.Sprintf("%#v", p)
  291. if s1 != s2 {
  292. t.Fatalf("GoString want %v got %v", s1, s2)
  293. }
  294. _, err := go_parser.ParseExpr(s1)
  295. if err != nil {
  296. t.Fatal(err)
  297. }
  298. }
  299. func TestSubbySize(t *testing.T) {
  300. seed := time.Now().UnixNano()
  301. popr := math_rand.New(math_rand.NewSource(seed))
  302. p := NewPopulatedSubby(popr, true)
  303. size2 := github_com_gogo_protobuf_proto.Size(p)
  304. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  305. if err != nil {
  306. t.Fatalf("seed = %d, err = %v", seed, err)
  307. }
  308. size := p.Size()
  309. if len(dAtA) != size {
  310. t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
  311. }
  312. if size2 != size {
  313. t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
  314. }
  315. size3 := github_com_gogo_protobuf_proto.Size(p)
  316. if size3 != size {
  317. t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
  318. }
  319. }
  320. func TestSampleOneOfSize(t *testing.T) {
  321. seed := time.Now().UnixNano()
  322. popr := math_rand.New(math_rand.NewSource(seed))
  323. p := NewPopulatedSampleOneOf(popr, true)
  324. size2 := github_com_gogo_protobuf_proto.Size(p)
  325. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  326. if err != nil {
  327. t.Fatalf("seed = %d, err = %v", seed, err)
  328. }
  329. size := p.Size()
  330. if len(dAtA) != size {
  331. t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
  332. }
  333. if size2 != size {
  334. t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
  335. }
  336. size3 := github_com_gogo_protobuf_proto.Size(p)
  337. if size3 != size {
  338. t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
  339. }
  340. }
  341. func TestSubbyStringer(t *testing.T) {
  342. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  343. p := NewPopulatedSubby(popr, false)
  344. s1 := p.String()
  345. s2 := fmt.Sprintf("%v", p)
  346. if s1 != s2 {
  347. t.Fatalf("String want %v got %v", s1, s2)
  348. }
  349. }
  350. func TestSampleOneOfStringer(t *testing.T) {
  351. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  352. p := NewPopulatedSampleOneOf(popr, false)
  353. s1 := p.String()
  354. s2 := fmt.Sprintf("%v", p)
  355. if s1 != s2 {
  356. t.Fatalf("String want %v got %v", s1, s2)
  357. }
  358. }
  359. //These tests are generated by github.com/gogo/protobuf/plugin/testgen