/Godeps/_workspace/src/github.com/gogo/protobuf/test/unmarshalmerge/unmarshalmergepb_test.go

https://gitlab.com/JamesClonk/firehose-to-syslog · Go · 477 lines · 443 code · 19 blank · 15 comment · 141 complexity · b3997b105d198c0fb20064a14ab3df96 MD5 · raw file

  1. // Code generated by protoc-gen-gogo.
  2. // source: unmarshalmerge.proto
  3. // DO NOT EDIT!
  4. /*
  5. Package unmarshalmerge is a generated protocol buffer package.
  6. It is generated from these files:
  7. unmarshalmerge.proto
  8. It has these top-level messages:
  9. Big
  10. BigUnsafe
  11. Sub
  12. */
  13. package unmarshalmerge
  14. import testing "testing"
  15. import math_rand "math/rand"
  16. import time "time"
  17. import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
  18. import encoding_json "encoding/json"
  19. import fmt "fmt"
  20. import go_parser "go/parser"
  21. func TestBigProto(t *testing.T) {
  22. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  23. p := NewPopulatedBig(popr, false)
  24. data, err := github_com_gogo_protobuf_proto.Marshal(p)
  25. if err != nil {
  26. panic(err)
  27. }
  28. msg := &Big{}
  29. if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
  30. panic(err)
  31. }
  32. for i := range data {
  33. data[i] = byte(popr.Intn(256))
  34. }
  35. if err := p.VerboseEqual(msg); err != nil {
  36. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  37. }
  38. if !p.Equal(msg) {
  39. t.Fatalf("%#v !Proto %#v", msg, p)
  40. }
  41. }
  42. func BenchmarkBigProtoMarshal(b *testing.B) {
  43. popr := math_rand.New(math_rand.NewSource(616))
  44. total := 0
  45. pops := make([]*Big, 10000)
  46. for i := 0; i < 10000; i++ {
  47. pops[i] = NewPopulatedBig(popr, false)
  48. }
  49. b.ResetTimer()
  50. for i := 0; i < b.N; i++ {
  51. data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
  52. if err != nil {
  53. panic(err)
  54. }
  55. total += len(data)
  56. }
  57. b.SetBytes(int64(total / b.N))
  58. }
  59. func BenchmarkBigProtoUnmarshal(b *testing.B) {
  60. popr := math_rand.New(math_rand.NewSource(616))
  61. total := 0
  62. datas := make([][]byte, 10000)
  63. for i := 0; i < 10000; i++ {
  64. data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedBig(popr, false))
  65. if err != nil {
  66. panic(err)
  67. }
  68. datas[i] = data
  69. }
  70. msg := &Big{}
  71. b.ResetTimer()
  72. for i := 0; i < b.N; i++ {
  73. total += len(datas[i%10000])
  74. if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
  75. panic(err)
  76. }
  77. }
  78. b.SetBytes(int64(total / b.N))
  79. }
  80. func TestBigUnsafeProto(t *testing.T) {
  81. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  82. p := NewPopulatedBigUnsafe(popr, false)
  83. data, err := github_com_gogo_protobuf_proto.Marshal(p)
  84. if err != nil {
  85. panic(err)
  86. }
  87. msg := &BigUnsafe{}
  88. if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
  89. panic(err)
  90. }
  91. for i := range data {
  92. data[i] = byte(popr.Intn(256))
  93. }
  94. if err := p.VerboseEqual(msg); err != nil {
  95. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  96. }
  97. if !p.Equal(msg) {
  98. t.Fatalf("%#v !Proto %#v", msg, p)
  99. }
  100. }
  101. func BenchmarkBigUnsafeProtoMarshal(b *testing.B) {
  102. popr := math_rand.New(math_rand.NewSource(616))
  103. total := 0
  104. pops := make([]*BigUnsafe, 10000)
  105. for i := 0; i < 10000; i++ {
  106. pops[i] = NewPopulatedBigUnsafe(popr, false)
  107. }
  108. b.ResetTimer()
  109. for i := 0; i < b.N; i++ {
  110. data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
  111. if err != nil {
  112. panic(err)
  113. }
  114. total += len(data)
  115. }
  116. b.SetBytes(int64(total / b.N))
  117. }
  118. func BenchmarkBigUnsafeProtoUnmarshal(b *testing.B) {
  119. popr := math_rand.New(math_rand.NewSource(616))
  120. total := 0
  121. datas := make([][]byte, 10000)
  122. for i := 0; i < 10000; i++ {
  123. data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedBigUnsafe(popr, false))
  124. if err != nil {
  125. panic(err)
  126. }
  127. datas[i] = data
  128. }
  129. msg := &BigUnsafe{}
  130. b.ResetTimer()
  131. for i := 0; i < b.N; i++ {
  132. total += len(datas[i%10000])
  133. if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
  134. panic(err)
  135. }
  136. }
  137. b.SetBytes(int64(total / b.N))
  138. }
  139. func TestSubProto(t *testing.T) {
  140. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  141. p := NewPopulatedSub(popr, false)
  142. data, err := github_com_gogo_protobuf_proto.Marshal(p)
  143. if err != nil {
  144. panic(err)
  145. }
  146. msg := &Sub{}
  147. if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
  148. panic(err)
  149. }
  150. for i := range data {
  151. data[i] = byte(popr.Intn(256))
  152. }
  153. if err := p.VerboseEqual(msg); err != nil {
  154. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  155. }
  156. if !p.Equal(msg) {
  157. t.Fatalf("%#v !Proto %#v", msg, p)
  158. }
  159. }
  160. func BenchmarkSubProtoMarshal(b *testing.B) {
  161. popr := math_rand.New(math_rand.NewSource(616))
  162. total := 0
  163. pops := make([]*Sub, 10000)
  164. for i := 0; i < 10000; i++ {
  165. pops[i] = NewPopulatedSub(popr, false)
  166. }
  167. b.ResetTimer()
  168. for i := 0; i < b.N; i++ {
  169. data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
  170. if err != nil {
  171. panic(err)
  172. }
  173. total += len(data)
  174. }
  175. b.SetBytes(int64(total / b.N))
  176. }
  177. func BenchmarkSubProtoUnmarshal(b *testing.B) {
  178. popr := math_rand.New(math_rand.NewSource(616))
  179. total := 0
  180. datas := make([][]byte, 10000)
  181. for i := 0; i < 10000; i++ {
  182. data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedSub(popr, false))
  183. if err != nil {
  184. panic(err)
  185. }
  186. datas[i] = data
  187. }
  188. msg := &Sub{}
  189. b.ResetTimer()
  190. for i := 0; i < b.N; i++ {
  191. total += len(datas[i%10000])
  192. if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
  193. panic(err)
  194. }
  195. }
  196. b.SetBytes(int64(total / b.N))
  197. }
  198. func TestBigJSON(t *testing.T) {
  199. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  200. p := NewPopulatedBig(popr, true)
  201. jsondata, err := encoding_json.Marshal(p)
  202. if err != nil {
  203. panic(err)
  204. }
  205. msg := &Big{}
  206. err = encoding_json.Unmarshal(jsondata, msg)
  207. if err != nil {
  208. panic(err)
  209. }
  210. if err := p.VerboseEqual(msg); err != nil {
  211. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  212. }
  213. if !p.Equal(msg) {
  214. t.Fatalf("%#v !Json Equal %#v", msg, p)
  215. }
  216. }
  217. func TestBigUnsafeJSON(t *testing.T) {
  218. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  219. p := NewPopulatedBigUnsafe(popr, true)
  220. jsondata, err := encoding_json.Marshal(p)
  221. if err != nil {
  222. panic(err)
  223. }
  224. msg := &BigUnsafe{}
  225. err = encoding_json.Unmarshal(jsondata, msg)
  226. if err != nil {
  227. panic(err)
  228. }
  229. if err := p.VerboseEqual(msg); err != nil {
  230. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  231. }
  232. if !p.Equal(msg) {
  233. t.Fatalf("%#v !Json Equal %#v", msg, p)
  234. }
  235. }
  236. func TestSubJSON(t *testing.T) {
  237. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  238. p := NewPopulatedSub(popr, true)
  239. jsondata, err := encoding_json.Marshal(p)
  240. if err != nil {
  241. panic(err)
  242. }
  243. msg := &Sub{}
  244. err = encoding_json.Unmarshal(jsondata, msg)
  245. if err != nil {
  246. panic(err)
  247. }
  248. if err := p.VerboseEqual(msg); err != nil {
  249. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  250. }
  251. if !p.Equal(msg) {
  252. t.Fatalf("%#v !Json Equal %#v", msg, p)
  253. }
  254. }
  255. func TestBigProtoText(t *testing.T) {
  256. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  257. p := NewPopulatedBig(popr, true)
  258. data := github_com_gogo_protobuf_proto.MarshalTextString(p)
  259. msg := &Big{}
  260. if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
  261. panic(err)
  262. }
  263. if err := p.VerboseEqual(msg); err != nil {
  264. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  265. }
  266. if !p.Equal(msg) {
  267. t.Fatalf("%#v !Proto %#v", msg, p)
  268. }
  269. }
  270. func TestBigProtoCompactText(t *testing.T) {
  271. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  272. p := NewPopulatedBig(popr, true)
  273. data := github_com_gogo_protobuf_proto.CompactTextString(p)
  274. msg := &Big{}
  275. if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
  276. panic(err)
  277. }
  278. if err := p.VerboseEqual(msg); err != nil {
  279. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  280. }
  281. if !p.Equal(msg) {
  282. t.Fatalf("%#v !Proto %#v", msg, p)
  283. }
  284. }
  285. func TestBigUnsafeProtoText(t *testing.T) {
  286. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  287. p := NewPopulatedBigUnsafe(popr, true)
  288. data := github_com_gogo_protobuf_proto.MarshalTextString(p)
  289. msg := &BigUnsafe{}
  290. if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
  291. panic(err)
  292. }
  293. if err := p.VerboseEqual(msg); err != nil {
  294. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  295. }
  296. if !p.Equal(msg) {
  297. t.Fatalf("%#v !Proto %#v", msg, p)
  298. }
  299. }
  300. func TestBigUnsafeProtoCompactText(t *testing.T) {
  301. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  302. p := NewPopulatedBigUnsafe(popr, true)
  303. data := github_com_gogo_protobuf_proto.CompactTextString(p)
  304. msg := &BigUnsafe{}
  305. if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
  306. panic(err)
  307. }
  308. if err := p.VerboseEqual(msg); err != nil {
  309. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  310. }
  311. if !p.Equal(msg) {
  312. t.Fatalf("%#v !Proto %#v", msg, p)
  313. }
  314. }
  315. func TestSubProtoText(t *testing.T) {
  316. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  317. p := NewPopulatedSub(popr, true)
  318. data := github_com_gogo_protobuf_proto.MarshalTextString(p)
  319. msg := &Sub{}
  320. if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
  321. panic(err)
  322. }
  323. if err := p.VerboseEqual(msg); err != nil {
  324. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  325. }
  326. if !p.Equal(msg) {
  327. t.Fatalf("%#v !Proto %#v", msg, p)
  328. }
  329. }
  330. func TestSubProtoCompactText(t *testing.T) {
  331. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  332. p := NewPopulatedSub(popr, true)
  333. data := github_com_gogo_protobuf_proto.CompactTextString(p)
  334. msg := &Sub{}
  335. if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
  336. panic(err)
  337. }
  338. if err := p.VerboseEqual(msg); err != nil {
  339. t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
  340. }
  341. if !p.Equal(msg) {
  342. t.Fatalf("%#v !Proto %#v", msg, p)
  343. }
  344. }
  345. func TestBigStringer(t *testing.T) {
  346. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  347. p := NewPopulatedBig(popr, false)
  348. s1 := p.String()
  349. s2 := fmt.Sprintf("%v", p)
  350. if s1 != s2 {
  351. t.Fatalf("String want %v got %v", s1, s2)
  352. }
  353. }
  354. func TestBigUnsafeStringer(t *testing.T) {
  355. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  356. p := NewPopulatedBigUnsafe(popr, false)
  357. s1 := p.String()
  358. s2 := fmt.Sprintf("%v", p)
  359. if s1 != s2 {
  360. t.Fatalf("String want %v got %v", s1, s2)
  361. }
  362. }
  363. func TestSubStringer(t *testing.T) {
  364. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  365. p := NewPopulatedSub(popr, false)
  366. s1 := p.String()
  367. s2 := fmt.Sprintf("%v", p)
  368. if s1 != s2 {
  369. t.Fatalf("String want %v got %v", s1, s2)
  370. }
  371. }
  372. func TestBigGoString(t *testing.T) {
  373. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  374. p := NewPopulatedBig(popr, false)
  375. s1 := p.GoString()
  376. s2 := fmt.Sprintf("%#v", p)
  377. if s1 != s2 {
  378. t.Fatalf("GoString want %v got %v", s1, s2)
  379. }
  380. _, err := go_parser.ParseExpr(s1)
  381. if err != nil {
  382. panic(err)
  383. }
  384. }
  385. func TestBigUnsafeGoString(t *testing.T) {
  386. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  387. p := NewPopulatedBigUnsafe(popr, false)
  388. s1 := p.GoString()
  389. s2 := fmt.Sprintf("%#v", p)
  390. if s1 != s2 {
  391. t.Fatalf("GoString want %v got %v", s1, s2)
  392. }
  393. _, err := go_parser.ParseExpr(s1)
  394. if err != nil {
  395. panic(err)
  396. }
  397. }
  398. func TestSubGoString(t *testing.T) {
  399. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  400. p := NewPopulatedSub(popr, false)
  401. s1 := p.GoString()
  402. s2 := fmt.Sprintf("%#v", p)
  403. if s1 != s2 {
  404. t.Fatalf("GoString want %v got %v", s1, s2)
  405. }
  406. _, err := go_parser.ParseExpr(s1)
  407. if err != nil {
  408. panic(err)
  409. }
  410. }
  411. func TestBigVerboseEqual(t *testing.T) {
  412. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  413. p := NewPopulatedBig(popr, false)
  414. data, err := github_com_gogo_protobuf_proto.Marshal(p)
  415. if err != nil {
  416. panic(err)
  417. }
  418. msg := &Big{}
  419. if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
  420. panic(err)
  421. }
  422. if err := p.VerboseEqual(msg); err != nil {
  423. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  424. }
  425. }
  426. func TestBigUnsafeVerboseEqual(t *testing.T) {
  427. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  428. p := NewPopulatedBigUnsafe(popr, false)
  429. data, err := github_com_gogo_protobuf_proto.Marshal(p)
  430. if err != nil {
  431. panic(err)
  432. }
  433. msg := &BigUnsafe{}
  434. if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
  435. panic(err)
  436. }
  437. if err := p.VerboseEqual(msg); err != nil {
  438. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  439. }
  440. }
  441. func TestSubVerboseEqual(t *testing.T) {
  442. popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
  443. p := NewPopulatedSub(popr, false)
  444. data, err := github_com_gogo_protobuf_proto.Marshal(p)
  445. if err != nil {
  446. panic(err)
  447. }
  448. msg := &Sub{}
  449. if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
  450. panic(err)
  451. }
  452. if err := p.VerboseEqual(msg); err != nil {
  453. t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
  454. }
  455. }
  456. //These tests are generated by github.com/gogo/protobuf/plugin/testgen