MCPcopy
hub / github.com/golang/protobuf / TestGetExtensionStability

Function TestGetExtensionStability

proto/extensions_test.go:183–215  ·  proto/extensions_test.go::TestGetExtensionStability
(t *testing.T)

Source from the content-addressed store, hash-verified

181}
182
183func TestGetExtensionStability(t *testing.T) {
184 check := func(m *pb2.MyMessage) bool {
185 ext1, err := proto.GetExtension(m, pb2.E_Ext_More)
186 if err != nil {
187 t.Fatalf("GetExtension() failed: %s", err)
188 }
189 ext2, err := proto.GetExtension(m, pb2.E_Ext_More)
190 if err != nil {
191 t.Fatalf("GetExtension() failed: %s", err)
192 }
193 return ext1 == ext2
194 }
195 msg := &pb2.MyMessage{Count: proto.Int32(4)}
196 ext0 := &pb2.Ext{}
197 if err := proto.SetExtension(msg, pb2.E_Ext_More, ext0); err != nil {
198 t.Fatalf("Could not set ext1: %s", ext0)
199 }
200 if !check(msg) {
201 t.Errorf("GetExtension() not stable before marshaling")
202 }
203 bb, err := proto.Marshal(msg)
204 if err != nil {
205 t.Fatalf("Marshal() failed: %s", err)
206 }
207 msg1 := &pb2.MyMessage{}
208 err = proto.Unmarshal(bb, msg1)
209 if err != nil {
210 t.Fatalf("Unmarshal() failed: %s", err)
211 }
212 if !check(msg1) {
213 t.Errorf("GetExtension() not stable after unmarshaling")
214 }
215}
216
217func TestGetExtensionDefaults(t *testing.T) {
218 var setFloat64 float64 = 1

Callers

nothing calls this directly

Calls 6

GetExtensionFunction · 0.92
Int32Function · 0.92
SetExtensionFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
checkFunction · 0.85

Tested by

no test coverage detected