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

Function TestAllSetDefaults

proto/proto_test.go:1325–1355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1323}
1324
1325func TestAllSetDefaults(t *testing.T) {
1326 // Exercise SetDefaults with all scalar field types.
1327 got := &pb2.Defaults{
1328 // NaN != NaN, so override that here.
1329 F_Nan: proto.Float32(1.7),
1330 }
1331 want := &pb2.Defaults{
1332 F_Bool: proto.Bool(true),
1333 F_Int32: proto.Int32(32),
1334 F_Int64: proto.Int64(64),
1335 F_Fixed32: proto.Uint32(320),
1336 F_Fixed64: proto.Uint64(640),
1337 F_Uint32: proto.Uint32(3200),
1338 F_Uint64: proto.Uint64(6400),
1339 F_Float: proto.Float32(314159),
1340 F_Double: proto.Float64(271828),
1341 F_String: proto.String(`hello, "world!"` + "\n"),
1342 F_Bytes: []byte("Bignose"),
1343 F_Sint32: proto.Int32(-32),
1344 F_Sint64: proto.Int64(-64),
1345 F_Enum: pb2.Defaults_GREEN.Enum(),
1346 F_Pinf: proto.Float32(float32(math.Inf(1))),
1347 F_Ninf: proto.Float32(float32(math.Inf(-1))),
1348 F_Nan: proto.Float32(1.7),
1349 StrZero: proto.String(""),
1350 }
1351 proto.SetDefaults(got)
1352 if !proto.Equal(got, want) {
1353 t.Errorf("SetDefaults failed\n got %v\nwant %v", got, want)
1354 }
1355}
1356
1357func TestSetDefaultsWithSetField(t *testing.T) {
1358 // Check that a set value is not overridden.

Callers

nothing calls this directly

Calls 11

Float32Function · 0.92
BoolFunction · 0.92
Int32Function · 0.92
Int64Function · 0.92
Uint32Function · 0.92
Uint64Function · 0.92
Float64Function · 0.92
StringFunction · 0.92
SetDefaultsFunction · 0.92
EqualFunction · 0.92
EnumMethod · 0.45

Tested by

no test coverage detected