(t *testing.T)
| 71 | } |
| 72 | |
| 73 | func TestDecodeAndEncode(t *testing.T) { |
| 74 | tests := []struct { |
| 75 | name string |
| 76 | v testStruct |
| 77 | opts jsp.Options |
| 78 | }{ |
| 79 | {name: "empty", v: testStruct{}, opts: jsp.Options{}}, |
| 80 | {name: "default", v: makeRandStruct(), opts: jsp.Options{}}, |
| 81 | {name: "compress", v: makeRandStruct(), opts: jsp.Options{Compress: true}}, |
| 82 | {name: "cksum", v: makeRandStruct(), opts: jsp.Options{Checksum: true}}, |
| 83 | {name: "sign", v: makeRandStruct(), opts: jsp.Options{Signature: true}}, |
| 84 | {name: "compress_cksum", v: makeRandStruct(), opts: jsp.Options{Compress: true, Checksum: true}}, |
| 85 | {name: "cksum_sign", v: makeRandStruct(), opts: jsp.Options{Checksum: true, Signature: true}}, |
| 86 | {name: "ccs", v: makeRandStruct(), opts: jsp.CCSign(1)}, |
| 87 | { |
| 88 | name: "special_char", |
| 89 | v: testStruct{I: 10, S: "abc\ncd]}{", B: []byte{'a', 'b', '\n', 'c', 'd', ']', '}'}}, |
| 90 | opts: jsp.Options{Checksum: true}, |
| 91 | }, |
| 92 | } |
| 93 | for _, test := range tests { |
| 94 | t.Run(test.name, func(t *testing.T) { |
| 95 | var ( |
| 96 | v testStruct |
| 97 | mmsa = memsys.PageMM() |
| 98 | b = mmsa.NewSGL(cos.MiB) |
| 99 | ) |
| 100 | defer b.Free() |
| 101 | |
| 102 | err := jsp.Encode(b, test.v, test.opts) |
| 103 | tassert.CheckFatal(t, err) |
| 104 | |
| 105 | _, err = jsp.Decode(b, &v, test.opts, "test") |
| 106 | tassert.CheckFatal(t, err) |
| 107 | |
| 108 | // reflect.DeepEqual may not work here due to using `[]byte` in the struct. |
| 109 | // `Decode` may generate empty slice from original `nil` slice and while |
| 110 | // both are kind of the same, DeepEqual says they differ. From output when |
| 111 | // the test fails: |
| 112 | // v(B:[]uint8(nil)) != test.v(B:[]uint8{}) |
| 113 | tassert.Fatalf( |
| 114 | t, v.equal(test.v), |
| 115 | "structs are not equal, (got: %+v, expected: %+v)", v, test.v, |
| 116 | ) |
| 117 | }) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func TestDecodeAndEncodeFuzz(t *testing.T) { |
| 122 | mmsa := memsys.PageMM() |
nothing calls this directly
no test coverage detected