/vendor/github.com/gogo/protobuf/test/castvalue/combos/unsafeunmarshaler/castvaluepb_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin · Go · 474 lines · 438 code · 19 blank · 17 comment · 128 complexity · c25866a075aa7bfdf4187555e89aa2e9 MD5 · raw file

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