/vendor/github.com/gogo/protobuf/test/casttype/combos/marshaler/casttypepb_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin · Go · 513 lines · 475 code · 21 blank · 17 comment · 138 complexity · bdff75f03e636d0fa04f26d6b19a31fc MD5 · raw file

  1. // Code generated by protoc-gen-gogo.
  2. // source: combos/marshaler/casttype.proto
  3. // DO NOT EDIT!
  4. /*
  5. Package casttype is a generated protocol buffer package.
  6. It is generated from these files:
  7. combos/marshaler/casttype.proto
  8. It has these top-level messages:
  9. Castaway
  10. Wilson
  11. */
  12. package casttype
  13. import testing "testing"
  14. import math_rand "math/rand"
  15. import time "time"
  16. import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
  17. import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb"
  18. import fmt "fmt"
  19. import go_parser "go/parser"
  20. import proto "github.com/gogo/protobuf/proto"
  21. import math "math"
  22. import _ "github.com/gogo/protobuf/gogoproto"
  23. // Reference imports to suppress errors if they are not otherwise used.
  24. var _ = proto.Marshal
  25. var _ = fmt.Errorf
  26. var _ = math.Inf
  27. func TestCastawayProto(t *testing.T) {
  28. seed := time.Now().UnixNano()
  29. popr := math_rand.New(math_rand.NewSource(seed))
  30. p := NewPopulatedCastaway(popr, false)
  31. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  32. if err != nil {
  33. t.Fatalf("seed = %d, err = %v", seed, err)
  34. }
  35. msg := &Castaway{}
  36. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  37. t.Fatalf("seed = %d, err = %v", seed, err)
  38. }
  39. littlefuzz := make([]byte, len(dAtA))
  40. copy(littlefuzz, dAtA)
  41. for i := range dAtA {
  42. dAtA[i] = byte(popr.Intn(256))
  43. }
  44. if err := p.VerboseEqual(msg); err != nil {
  45. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  46. }
  47. if !p.Equal(msg) {
  48. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  49. }
  50. if len(littlefuzz) > 0 {
  51. fuzzamount := 100
  52. for i := 0; i < fuzzamount; i++ {
  53. littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
  54. littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
  55. }
  56. // shouldn't panic
  57. _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
  58. }
  59. }
  60. func TestCastawayMarshalTo(t *testing.T) {
  61. seed := time.Now().UnixNano()
  62. popr := math_rand.New(math_rand.NewSource(seed))
  63. p := NewPopulatedCastaway(popr, false)
  64. size := p.Size()
  65. dAtA := make([]byte, size)
  66. for i := range dAtA {
  67. dAtA[i] = byte(popr.Intn(256))
  68. }
  69. _, err := p.MarshalTo(dAtA)
  70. if err != nil {
  71. t.Fatalf("seed = %d, err = %v", seed, err)
  72. }
  73. msg := &Castaway{}
  74. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  75. t.Fatalf("seed = %d, err = %v", seed, err)
  76. }
  77. for i := range dAtA {
  78. dAtA[i] = byte(popr.Intn(256))
  79. }
  80. if err := p.VerboseEqual(msg); err != nil {
  81. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  82. }
  83. if !p.Equal(msg) {
  84. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  85. }
  86. }
  87. func BenchmarkCastawayProtoMarshal(b *testing.B) {
  88. popr := math_rand.New(math_rand.NewSource(616))
  89. total := 0
  90. pops := make([]*Castaway, 10000)
  91. for i := 0; i < 10000; i++ {
  92. pops[i] = NewPopulatedCastaway(popr, false)
  93. }
  94. b.ResetTimer()
  95. for i := 0; i < b.N; i++ {
  96. dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
  97. if err != nil {
  98. panic(err)
  99. }
  100. total += len(dAtA)
  101. }
  102. b.SetBytes(int64(total / b.N))
  103. }
  104. func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
  105. popr := math_rand.New(math_rand.NewSource(616))
  106. total := 0
  107. datas := make([][]byte, 10000)
  108. for i := 0; i < 10000; i++ {
  109. dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false))
  110. if err != nil {
  111. panic(err)
  112. }
  113. datas[i] = dAtA
  114. }
  115. msg := &Castaway{}
  116. b.ResetTimer()
  117. for i := 0; i < b.N; i++ {
  118. total += len(datas[i%10000])
  119. if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
  120. panic(err)
  121. }
  122. }
  123. b.SetBytes(int64(total / b.N))
  124. }
  125. func TestWilsonProto(t *testing.T) {
  126. seed := time.Now().UnixNano()
  127. popr := math_rand.New(math_rand.NewSource(seed))
  128. p := NewPopulatedWilson(popr, false)
  129. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  130. if err != nil {
  131. t.Fatalf("seed = %d, err = %v", seed, err)
  132. }
  133. msg := &Wilson{}
  134. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  135. t.Fatalf("seed = %d, err = %v", seed, err)
  136. }
  137. littlefuzz := make([]byte, len(dAtA))
  138. copy(littlefuzz, dAtA)
  139. for i := range dAtA {
  140. dAtA[i] = byte(popr.Intn(256))
  141. }
  142. if err := p.VerboseEqual(msg); err != nil {
  143. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  144. }
  145. if !p.Equal(msg) {
  146. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  147. }
  148. if len(littlefuzz) > 0 {
  149. fuzzamount := 100
  150. for i := 0; i < fuzzamount; i++ {
  151. littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
  152. littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
  153. }
  154. // shouldn't panic
  155. _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
  156. }
  157. }
  158. func TestWilsonMarshalTo(t *testing.T) {
  159. seed := time.Now().UnixNano()
  160. popr := math_rand.New(math_rand.NewSource(seed))
  161. p := NewPopulatedWilson(popr, false)
  162. size := p.Size()
  163. dAtA := make([]byte, size)
  164. for i := range dAtA {
  165. dAtA[i] = byte(popr.Intn(256))
  166. }
  167. _, err := p.MarshalTo(dAtA)
  168. if err != nil {
  169. t.Fatalf("seed = %d, err = %v", seed, err)
  170. }
  171. msg := &Wilson{}
  172. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  173. t.Fatalf("seed = %d, err = %v", seed, err)
  174. }
  175. for i := range dAtA {
  176. dAtA[i] = byte(popr.Intn(256))
  177. }
  178. if err := p.VerboseEqual(msg); err != nil {
  179. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  180. }
  181. if !p.Equal(msg) {
  182. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  183. }
  184. }
  185. func BenchmarkWilsonProtoMarshal(b *testing.B) {
  186. popr := math_rand.New(math_rand.NewSource(616))
  187. total := 0
  188. pops := make([]*Wilson, 10000)
  189. for i := 0; i < 10000; i++ {
  190. pops[i] = NewPopulatedWilson(popr, false)
  191. }
  192. b.ResetTimer()
  193. for i := 0; i < b.N; i++ {
  194. dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
  195. if err != nil {
  196. panic(err)
  197. }
  198. total += len(dAtA)
  199. }
  200. b.SetBytes(int64(total / b.N))
  201. }
  202. func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
  203. popr := math_rand.New(math_rand.NewSource(616))
  204. total := 0
  205. datas := make([][]byte, 10000)
  206. for i := 0; i < 10000; i++ {
  207. dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false))
  208. if err != nil {
  209. panic(err)
  210. }
  211. datas[i] = dAtA
  212. }
  213. msg := &Wilson{}
  214. b.ResetTimer()
  215. for i := 0; i < b.N; i++ {
  216. total += len(datas[i%10000])
  217. if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
  218. panic(err)
  219. }
  220. }
  221. b.SetBytes(int64(total / b.N))
  222. }
  223. func TestCastawayJSON(t *testing.T) {
  224. seed := time.Now().UnixNano()
  225. popr := math_rand.New(math_rand.NewSource(seed))
  226. p := NewPopulatedCastaway(popr, true)
  227. marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
  228. jsondata, err := marshaler.MarshalToString(p)
  229. if err != nil {
  230. t.Fatalf("seed = %d, err = %v", seed, err)
  231. }
  232. msg := &Castaway{}
  233. err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
  234. if err != nil {
  235. t.Fatalf("seed = %d, err = %v", seed, err)
  236. }
  237. if err := p.VerboseEqual(msg); err != nil {
  238. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  239. }
  240. if !p.Equal(msg) {
  241. t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
  242. }
  243. }
  244. func TestWilsonJSON(t *testing.T) {
  245. seed := time.Now().UnixNano()
  246. popr := math_rand.New(math_rand.NewSource(seed))
  247. p := NewPopulatedWilson(popr, true)
  248. marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
  249. jsondata, err := marshaler.MarshalToString(p)
  250. if err != nil {
  251. t.Fatalf("seed = %d, err = %v", seed, err)
  252. }
  253. msg := &Wilson{}
  254. err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
  255. if err != nil {
  256. t.Fatalf("seed = %d, err = %v", seed, err)
  257. }
  258. if err := p.VerboseEqual(msg); err != nil {
  259. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  260. }
  261. if !p.Equal(msg) {
  262. t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
  263. }
  264. }
  265. func TestCastawayProtoText(t *testing.T) {
  266. seed := time.Now().UnixNano()
  267. popr := math_rand.New(math_rand.NewSource(seed))
  268. p := NewPopulatedCastaway(popr, true)
  269. dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
  270. msg := &Castaway{}
  271. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  272. t.Fatalf("seed = %d, err = %v", seed, err)
  273. }
  274. if err := p.VerboseEqual(msg); err != nil {
  275. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  276. }
  277. if !p.Equal(msg) {
  278. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  279. }
  280. }
  281. func TestCastawayProtoCompactText(t *testing.T) {
  282. seed := time.Now().UnixNano()
  283. popr := math_rand.New(math_rand.NewSource(seed))
  284. p := NewPopulatedCastaway(popr, true)
  285. dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
  286. msg := &Castaway{}
  287. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  288. t.Fatalf("seed = %d, err = %v", seed, err)
  289. }
  290. if err := p.VerboseEqual(msg); err != nil {
  291. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  292. }
  293. if !p.Equal(msg) {
  294. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  295. }
  296. }
  297. func TestWilsonProtoText(t *testing.T) {
  298. seed := time.Now().UnixNano()
  299. popr := math_rand.New(math_rand.NewSource(seed))
  300. p := NewPopulatedWilson(popr, true)
  301. dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
  302. msg := &Wilson{}
  303. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  304. t.Fatalf("seed = %d, err = %v", seed, err)
  305. }
  306. if err := p.VerboseEqual(msg); err != nil {
  307. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  308. }
  309. if !p.Equal(msg) {
  310. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  311. }
  312. }
  313. func TestWilsonProtoCompactText(t *testing.T) {
  314. seed := time.Now().UnixNano()
  315. popr := math_rand.New(math_rand.NewSource(seed))
  316. p := NewPopulatedWilson(popr, true)
  317. dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
  318. msg := &Wilson{}
  319. if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
  320. t.Fatalf("seed = %d, err = %v", seed, err)
  321. }
  322. if err := p.VerboseEqual(msg); err != nil {
  323. t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
  324. }
  325. if !p.Equal(msg) {
  326. t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
  327. }
  328. }
  329. func TestCasttypeDescription(t *testing.T) {
  330. CasttypeDescription()
  331. }
  332. func TestCastawayVerboseEqual(t *testing.T) {
  333. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  334. p := NewPopulatedCastaway(popr, false)
  335. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  336. if err != nil {
  337. panic(err)
  338. }
  339. msg := &Castaway{}
  340. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  341. panic(err)
  342. }
  343. if err := p.VerboseEqual(msg); err != nil {
  344. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  345. }
  346. }
  347. func TestWilsonVerboseEqual(t *testing.T) {
  348. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  349. p := NewPopulatedWilson(popr, false)
  350. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  351. if err != nil {
  352. panic(err)
  353. }
  354. msg := &Wilson{}
  355. if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
  356. panic(err)
  357. }
  358. if err := p.VerboseEqual(msg); err != nil {
  359. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  360. }
  361. }
  362. func TestCastawayFace(t *testing.T) {
  363. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  364. p := NewPopulatedCastaway(popr, true)
  365. msg := p.TestProto()
  366. if !p.Equal(msg) {
  367. t.Fatalf("%#v !Face Equal %#v", msg, p)
  368. }
  369. }
  370. func TestWilsonFace(t *testing.T) {
  371. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  372. p := NewPopulatedWilson(popr, true)
  373. msg := p.TestProto()
  374. if !p.Equal(msg) {
  375. t.Fatalf("%#v !Face Equal %#v", msg, p)
  376. }
  377. }
  378. func TestCastawayGoString(t *testing.T) {
  379. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  380. p := NewPopulatedCastaway(popr, false)
  381. s1 := p.GoString()
  382. s2 := fmt.Sprintf("%#v", p)
  383. if s1 != s2 {
  384. t.Fatalf("GoString want %v got %v", s1, s2)
  385. }
  386. _, err := go_parser.ParseExpr(s1)
  387. if err != nil {
  388. panic(err)
  389. }
  390. }
  391. func TestWilsonGoString(t *testing.T) {
  392. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  393. p := NewPopulatedWilson(popr, false)
  394. s1 := p.GoString()
  395. s2 := fmt.Sprintf("%#v", p)
  396. if s1 != s2 {
  397. t.Fatalf("GoString want %v got %v", s1, s2)
  398. }
  399. _, err := go_parser.ParseExpr(s1)
  400. if err != nil {
  401. panic(err)
  402. }
  403. }
  404. func TestCastawaySize(t *testing.T) {
  405. seed := time.Now().UnixNano()
  406. popr := math_rand.New(math_rand.NewSource(seed))
  407. p := NewPopulatedCastaway(popr, true)
  408. size2 := github_com_gogo_protobuf_proto.Size(p)
  409. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  410. if err != nil {
  411. t.Fatalf("seed = %d, err = %v", seed, err)
  412. }
  413. size := p.Size()
  414. if len(dAtA) != size {
  415. t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
  416. }
  417. if size2 != size {
  418. t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
  419. }
  420. size3 := github_com_gogo_protobuf_proto.Size(p)
  421. if size3 != size {
  422. t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
  423. }
  424. }
  425. func BenchmarkCastawaySize(b *testing.B) {
  426. popr := math_rand.New(math_rand.NewSource(616))
  427. total := 0
  428. pops := make([]*Castaway, 1000)
  429. for i := 0; i < 1000; i++ {
  430. pops[i] = NewPopulatedCastaway(popr, false)
  431. }
  432. b.ResetTimer()
  433. for i := 0; i < b.N; i++ {
  434. total += pops[i%1000].Size()
  435. }
  436. b.SetBytes(int64(total / b.N))
  437. }
  438. func TestWilsonSize(t *testing.T) {
  439. seed := time.Now().UnixNano()
  440. popr := math_rand.New(math_rand.NewSource(seed))
  441. p := NewPopulatedWilson(popr, true)
  442. size2 := github_com_gogo_protobuf_proto.Size(p)
  443. dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
  444. if err != nil {
  445. t.Fatalf("seed = %d, err = %v", seed, err)
  446. }
  447. size := p.Size()
  448. if len(dAtA) != size {
  449. t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
  450. }
  451. if size2 != size {
  452. t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
  453. }
  454. size3 := github_com_gogo_protobuf_proto.Size(p)
  455. if size3 != size {
  456. t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
  457. }
  458. }
  459. func BenchmarkWilsonSize(b *testing.B) {
  460. popr := math_rand.New(math_rand.NewSource(616))
  461. total := 0
  462. pops := make([]*Wilson, 1000)
  463. for i := 0; i < 1000; i++ {
  464. pops[i] = NewPopulatedWilson(popr, false)
  465. }
  466. b.ResetTimer()
  467. for i := 0; i < b.N; i++ {
  468. total += pops[i%1000].Size()
  469. }
  470. b.SetBytes(int64(total / b.N))
  471. }
  472. func TestCastawayStringer(t *testing.T) {
  473. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  474. p := NewPopulatedCastaway(popr, false)
  475. s1 := p.String()
  476. s2 := fmt.Sprintf("%v", p)
  477. if s1 != s2 {
  478. t.Fatalf("String want %v got %v", s1, s2)
  479. }
  480. }
  481. func TestWilsonStringer(t *testing.T) {
  482. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  483. p := NewPopulatedWilson(popr, false)
  484. s1 := p.String()
  485. s2 := fmt.Sprintf("%v", p)
  486. if s1 != s2 {
  487. t.Fatalf("String want %v got %v", s1, s2)
  488. }
  489. }
  490. //These tests are generated by github.com/gogo/protobuf/plugin/testgen