...
1
2
3
4
5 package proto_test
6
7 import (
8 "fmt"
9 "testing"
10
11 "google.golang.org/protobuf/internal/impl"
12 piface "google.golang.org/protobuf/runtime/protoiface"
13 )
14
15
16
17
18
19
20 func TestValidateValid(t *testing.T) {
21 for _, test := range testValidMessages {
22 for _, m := range test.decodeTo {
23 t.Run(fmt.Sprintf("%s (%T)", test.desc, m), func(t *testing.T) {
24 mt := m.ProtoReflect().Type()
25 want := impl.ValidationValid
26 if test.validationStatus != 0 {
27 want = test.validationStatus
28 }
29 out, status := impl.Validate(mt, piface.UnmarshalInput{
30 Buf: test.wire,
31 })
32 if status != want {
33 t.Errorf("Validate(%x) = %v, want %v", test.wire, status, want)
34 }
35 if got, want := (out.Flags&piface.UnmarshalInitialized != 0), !test.partial; got != want && !test.nocheckValidInit && status == impl.ValidationValid {
36 t.Errorf("Validate(%x): initialized = %v, want %v", test.wire, got, want)
37 }
38 })
39 }
40 }
41 }
42
43 func TestValidateInvalid(t *testing.T) {
44 for _, test := range testInvalidMessages {
45 for _, m := range test.decodeTo {
46 t.Run(fmt.Sprintf("%s (%T)", test.desc, m), func(t *testing.T) {
47 mt := m.ProtoReflect().Type()
48 _, got := impl.Validate(mt, piface.UnmarshalInput{
49 Buf: test.wire,
50 })
51 want := impl.ValidationInvalid
52 if got != want {
53 t.Errorf("Validate(%x) = %v, want %v", test.wire, got, want)
54 }
55 })
56 }
57 }
58 }
59
View as plain text