Check that we can grow an array (repeated field) to have many elements. This test doesn't depend only on our encoding; for variety, it makes sure we create, encode, and decode the correct contents explicitly. It's therefore a bit messier. This test also uses (and hence tests) the Marshal/Unmarshal
(t *testing.T)
| 1018 | // This test also uses (and hence tests) the Marshal/Unmarshal functions |
| 1019 | // instead of the methods. |
| 1020 | func TestBigRepeated(t *testing.T) { |
| 1021 | pb := initGoTest(true) |
| 1022 | |
| 1023 | // Create the arrays |
| 1024 | const N = 50 // Internally the library starts much smaller. |
| 1025 | pb.Repeatedgroup = make([]*pb2.GoTest_RepeatedGroup, N) |
| 1026 | pb.F_Sint64Repeated = make([]int64, N) |
| 1027 | pb.F_Sint32Repeated = make([]int32, N) |
| 1028 | pb.F_BytesRepeated = make([][]byte, N) |
| 1029 | pb.F_StringRepeated = make([]string, N) |
| 1030 | pb.F_DoubleRepeated = make([]float64, N) |
| 1031 | pb.F_FloatRepeated = make([]float32, N) |
| 1032 | pb.F_Uint64Repeated = make([]uint64, N) |
| 1033 | pb.F_Uint32Repeated = make([]uint32, N) |
| 1034 | pb.F_Fixed64Repeated = make([]uint64, N) |
| 1035 | pb.F_Fixed32Repeated = make([]uint32, N) |
| 1036 | pb.F_Int64Repeated = make([]int64, N) |
| 1037 | pb.F_Int32Repeated = make([]int32, N) |
| 1038 | pb.F_BoolRepeated = make([]bool, N) |
| 1039 | pb.RepeatedField = make([]*pb2.GoTestField, N) |
| 1040 | |
| 1041 | // Fill in the arrays with checkable values. |
| 1042 | igtf := initGoTestField() |
| 1043 | igtrg := initGoTest_RepeatedGroup() |
| 1044 | for i := 0; i < N; i++ { |
| 1045 | pb.Repeatedgroup[i] = igtrg |
| 1046 | pb.F_Sint64Repeated[i] = int64(i) |
| 1047 | pb.F_Sint32Repeated[i] = int32(i) |
| 1048 | s := fmt.Sprint(i) |
| 1049 | pb.F_BytesRepeated[i] = []byte(s) |
| 1050 | pb.F_StringRepeated[i] = s |
| 1051 | pb.F_DoubleRepeated[i] = float64(i) |
| 1052 | pb.F_FloatRepeated[i] = float32(i) |
| 1053 | pb.F_Uint64Repeated[i] = uint64(i) |
| 1054 | pb.F_Uint32Repeated[i] = uint32(i) |
| 1055 | pb.F_Fixed64Repeated[i] = uint64(i) |
| 1056 | pb.F_Fixed32Repeated[i] = uint32(i) |
| 1057 | pb.F_Int64Repeated[i] = int64(i) |
| 1058 | pb.F_Int32Repeated[i] = int32(i) |
| 1059 | pb.F_BoolRepeated[i] = i%2 == 0 |
| 1060 | pb.RepeatedField[i] = igtf |
| 1061 | } |
| 1062 | |
| 1063 | // Marshal. |
| 1064 | buf, _ := proto.Marshal(pb) |
| 1065 | |
| 1066 | // Now test Unmarshal by recreating the original buffer. |
| 1067 | pbd := new(pb2.GoTest) |
| 1068 | proto.Unmarshal(buf, pbd) |
| 1069 | |
| 1070 | // Check the checkable values |
| 1071 | for i := uint64(0); i < N; i++ { |
| 1072 | switch { |
| 1073 | case pbd.Repeatedgroup[i] == nil: |
| 1074 | t.Error("pbd.Repeatedgroup bad") |
| 1075 | case uint64(pbd.F_Sint64Repeated[i]) != i: |
| 1076 | t.Error("pbd.F_Sint64Repeated bad", uint64(pbd.F_Sint64Repeated[i]), i) |
| 1077 | case uint64(pbd.F_Sint32Repeated[i]) != i: |
nothing calls this directly
no test coverage detected