parent
9053033a50
commit
09354db143
272 changed files with 21132 additions and 5855 deletions
@ -1,17 +1,616 @@ |
||||
Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput |
||||
Recommended.FieldMaskPathsDontRoundTrip.JsonOutput |
||||
Recommended.FieldMaskTooManyUnderscore.JsonOutput |
||||
Recommended.JsonInput.BoolFieldAllCapitalFalse |
||||
Recommended.JsonInput.BoolFieldAllCapitalTrue |
||||
Recommended.JsonInput.BoolFieldCamelCaseFalse |
||||
Recommended.JsonInput.BoolFieldCamelCaseTrue |
||||
Recommended.JsonInput.BoolFieldDoubleQuotedFalse |
||||
Recommended.JsonInput.BoolFieldDoubleQuotedTrue |
||||
Recommended.JsonInput.BoolFieldIntegerOne |
||||
Recommended.JsonInput.BoolFieldIntegerZero |
||||
Recommended.JsonInput.BoolMapFieldKeyNotQuoted |
||||
Recommended.JsonInput.BytesFieldBase64Url.JsonOutput |
||||
Recommended.JsonInput.BytesFieldBase64Url.ProtobufOutput |
||||
Recommended.JsonInput.DoubleFieldInfinityNotQuoted |
||||
Recommended.JsonInput.DoubleFieldNanNotQuoted |
||||
Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted |
||||
Recommended.JsonInput.DurationHas3FractionalDigits.Validator |
||||
Recommended.JsonInput.DurationHas6FractionalDigits.Validator |
||||
Recommended.JsonInput.DurationHas9FractionalDigits.Validator |
||||
Recommended.JsonInput.DurationHasZeroFractionalDigit.Validator |
||||
Recommended.JsonInput.FieldMaskInvalidCharacter |
||||
Recommended.JsonInput.FieldNameDuplicate |
||||
Recommended.JsonInput.FieldNameDuplicateDifferentCasing1 |
||||
Recommended.JsonInput.FieldNameDuplicateDifferentCasing2 |
||||
Recommended.JsonInput.FieldNameNotQuoted |
||||
Recommended.JsonInput.FieldNameWithDoubleUnderscores.JsonOutput |
||||
Recommended.JsonInput.FieldNameWithDoubleUnderscores.ProtobufOutput |
||||
Recommended.JsonInput.FieldNameWithDoubleUnderscores.Validator |
||||
Recommended.JsonInput.FloatFieldInfinityNotQuoted |
||||
Recommended.JsonInput.FloatFieldNanNotQuoted |
||||
Recommended.JsonInput.FloatFieldNegativeInfinityNotQuoted |
||||
Required.JsonInput.BytesFieldInvalidBase64Characters |
||||
Recommended.JsonInput.Int32MapFieldKeyNotQuoted |
||||
Recommended.JsonInput.Int64FieldBeString.Validator |
||||
Recommended.JsonInput.Int64MapFieldKeyNotQuoted |
||||
Recommended.JsonInput.JsonWithComments |
||||
Recommended.JsonInput.MapFieldKeyIsNull |
||||
Recommended.JsonInput.MapFieldValueIsNull |
||||
Recommended.JsonInput.MissingCommaMultiline |
||||
Recommended.JsonInput.MissingCommaOneLine |
||||
Recommended.JsonInput.MultilineNoSpaces.JsonOutput |
||||
Recommended.JsonInput.MultilineNoSpaces.ProtobufOutput |
||||
Recommended.JsonInput.MultilineWithSpaces.JsonOutput |
||||
Recommended.JsonInput.MultilineWithSpaces.ProtobufOutput |
||||
Recommended.JsonInput.OneLineNoSpaces.JsonOutput |
||||
Recommended.JsonInput.OneLineNoSpaces.ProtobufOutput |
||||
Recommended.JsonInput.OneLineWithSpaces.JsonOutput |
||||
Recommended.JsonInput.OneLineWithSpaces.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroBool.JsonOutput |
||||
Recommended.JsonInput.OneofZeroBool.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroBytes.JsonOutput |
||||
Recommended.JsonInput.OneofZeroBytes.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroDouble.JsonOutput |
||||
Recommended.JsonInput.OneofZeroDouble.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroEnum.JsonOutput |
||||
Recommended.JsonInput.OneofZeroEnum.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroFloat.JsonOutput |
||||
Recommended.JsonInput.OneofZeroFloat.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroMessage.JsonOutput |
||||
Recommended.JsonInput.OneofZeroMessage.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroString.JsonOutput |
||||
Recommended.JsonInput.OneofZeroString.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroUint32.JsonOutput |
||||
Recommended.JsonInput.OneofZeroUint32.ProtobufOutput |
||||
Recommended.JsonInput.OneofZeroUint64.JsonOutput |
||||
Recommended.JsonInput.OneofZeroUint64.ProtobufOutput |
||||
Recommended.JsonInput.RepeatedFieldMessageElementIsNull |
||||
Recommended.JsonInput.RepeatedFieldPrimitiveElementIsNull |
||||
Recommended.JsonInput.RepeatedFieldTrailingComma |
||||
Recommended.JsonInput.RepeatedFieldTrailingCommaWithNewlines |
||||
Recommended.JsonInput.RepeatedFieldTrailingCommaWithSpace |
||||
Recommended.JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace |
||||
Recommended.JsonInput.StringEndsWithEscapeChar |
||||
Recommended.JsonInput.StringFieldInvalidEscape |
||||
Recommended.JsonInput.StringFieldSingleQuoteBoth |
||||
Recommended.JsonInput.StringFieldSingleQuoteKey |
||||
Recommended.JsonInput.StringFieldSingleQuoteValue |
||||
Recommended.JsonInput.StringFieldSurrogateInWrongOrder |
||||
Recommended.JsonInput.StringFieldUnpairedHighSurrogate |
||||
Recommended.JsonInput.StringFieldUnpairedLowSurrogate |
||||
Recommended.JsonInput.StringFieldUnterminatedEscape |
||||
Recommended.JsonInput.StringFieldUppercaseEscapeLetter |
||||
Recommended.JsonInput.TimestampHas3FractionalDigits.Validator |
||||
Recommended.JsonInput.TimestampHas6FractionalDigits.Validator |
||||
Recommended.JsonInput.TimestampHas9FractionalDigits.Validator |
||||
Recommended.JsonInput.TimestampHasZeroFractionalDigit.Validator |
||||
Recommended.JsonInput.TimestampZeroNormalized.Validator |
||||
Recommended.JsonInput.TrailingCommaInAnObject |
||||
Recommended.JsonInput.TrailingCommaInAnObjectWithNewlines |
||||
Recommended.JsonInput.TrailingCommaInAnObjectWithSpace |
||||
Recommended.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace |
||||
Recommended.JsonInput.Uint32MapFieldKeyNotQuoted |
||||
Recommended.JsonInput.Uint64FieldBeString.Validator |
||||
Recommended.JsonInput.Uint64MapFieldKeyNotQuoted |
||||
Recommended.ProtobufInput.OneofZeroBool.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroBool.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroBytes.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroBytes.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroDouble.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroDouble.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroEnum.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroEnum.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroFloat.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroFloat.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroMessage.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroMessage.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroString.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroString.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroUint32.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroUint32.ProtobufOutput |
||||
Recommended.ProtobufInput.OneofZeroUint64.JsonOutput |
||||
Recommended.ProtobufInput.OneofZeroUint64.ProtobufOutput |
||||
Required.DurationProtoInputTooLarge.JsonOutput |
||||
Required.DurationProtoInputTooSmall.JsonOutput |
||||
Required.JsonInput.AllFieldAcceptNull.JsonOutput |
||||
Required.JsonInput.AllFieldAcceptNull.ProtobufOutput |
||||
Required.JsonInput.Any.JsonOutput |
||||
Required.JsonInput.Any.ProtobufOutput |
||||
Required.JsonInput.AnyNested.JsonOutput |
||||
Required.JsonInput.AnyNested.ProtobufOutput |
||||
Required.JsonInput.AnyUnorderedTypeTag.JsonOutput |
||||
Required.JsonInput.AnyUnorderedTypeTag.ProtobufOutput |
||||
Required.JsonInput.AnyWithDuration.JsonOutput |
||||
Required.JsonInput.AnyWithDuration.ProtobufOutput |
||||
Required.JsonInput.AnyWithFieldMask.JsonOutput |
||||
Required.JsonInput.AnyWithFieldMask.ProtobufOutput |
||||
Required.JsonInput.AnyWithInt32ValueWrapper.JsonOutput |
||||
Required.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput |
||||
Required.JsonInput.AnyWithStruct.JsonOutput |
||||
Required.JsonInput.AnyWithStruct.ProtobufOutput |
||||
Required.JsonInput.AnyWithTimestamp.JsonOutput |
||||
Required.JsonInput.AnyWithTimestamp.ProtobufOutput |
||||
Required.JsonInput.AnyWithValueForInteger.JsonOutput |
||||
Required.JsonInput.AnyWithValueForInteger.ProtobufOutput |
||||
Required.JsonInput.AnyWithValueForJsonObject.JsonOutput |
||||
Required.JsonInput.AnyWithValueForJsonObject.ProtobufOutput |
||||
Required.JsonInput.BoolFieldFalse.JsonOutput |
||||
Required.JsonInput.BoolFieldFalse.ProtobufOutput |
||||
Required.JsonInput.BoolFieldTrue.JsonOutput |
||||
Required.JsonInput.BoolFieldTrue.ProtobufOutput |
||||
Required.JsonInput.BoolMapEscapedKey.JsonOutput |
||||
Required.JsonInput.BoolMapEscapedKey.ProtobufOutput |
||||
Required.JsonInput.BoolMapField.JsonOutput |
||||
Required.JsonInput.BoolMapField.ProtobufOutput |
||||
Required.JsonInput.BytesField.JsonOutput |
||||
Required.JsonInput.BytesField.ProtobufOutput |
||||
Required.JsonInput.BytesRepeatedField.JsonOutput |
||||
Required.JsonInput.BytesRepeatedField.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldInfinity.JsonOutput |
||||
Required.JsonInput.DoubleFieldInfinity.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput |
||||
Required.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldMaxPositiveValue.JsonOutput |
||||
Required.JsonInput.DoubleFieldMaxPositiveValue.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldMinNegativeValue.JsonOutput |
||||
Required.JsonInput.DoubleFieldMinNegativeValue.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldMinPositiveValue.JsonOutput |
||||
Required.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldNan.JsonOutput |
||||
Required.JsonInput.DoubleFieldNan.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldNegativeInfinity.JsonOutput |
||||
Required.JsonInput.DoubleFieldNegativeInfinity.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldQuotedValue.JsonOutput |
||||
Required.JsonInput.DoubleFieldQuotedValue.ProtobufOutput |
||||
Required.JsonInput.DoubleFieldTooLarge |
||||
Required.JsonInput.DoubleFieldTooSmall |
||||
Required.JsonInput.DurationJsonInputTooLarge |
||||
Required.JsonInput.DurationJsonInputTooSmall |
||||
Required.JsonInput.DurationMaxValue.JsonOutput |
||||
Required.JsonInput.DurationMaxValue.ProtobufOutput |
||||
Required.JsonInput.DurationMinValue.JsonOutput |
||||
Required.JsonInput.DurationMinValue.ProtobufOutput |
||||
Required.JsonInput.DurationMissingS |
||||
Required.JsonInput.DurationRepeatedValue.JsonOutput |
||||
Required.JsonInput.DurationRepeatedValue.ProtobufOutput |
||||
Required.JsonInput.EnumField.JsonOutput |
||||
Required.JsonInput.EnumField.ProtobufOutput |
||||
Required.JsonInput.EnumFieldNotQuoted |
||||
Required.JsonInput.EnumFieldNumericValueNonZero.JsonOutput |
||||
Required.JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput |
||||
Required.JsonInput.EnumFieldNumericValueZero.JsonOutput |
||||
Required.JsonInput.EnumFieldNumericValueZero.ProtobufOutput |
||||
Required.JsonInput.EnumFieldUnknownValue.Validator |
||||
Required.JsonInput.EnumRepeatedField.JsonOutput |
||||
Required.JsonInput.EnumRepeatedField.ProtobufOutput |
||||
Required.JsonInput.FieldMask.JsonOutput |
||||
Required.JsonInput.FieldMask.ProtobufOutput |
||||
Required.JsonInput.FieldNameEscaped.JsonOutput |
||||
Required.JsonInput.FieldNameEscaped.ProtobufOutput |
||||
Required.JsonInput.FieldNameInLowerCamelCase.Validator |
||||
Required.JsonInput.FieldNameInSnakeCase.JsonOutput |
||||
Required.JsonInput.FieldNameInSnakeCase.ProtobufOutput |
||||
Required.JsonInput.FieldNameWithMixedCases.JsonOutput |
||||
Required.JsonInput.FieldNameWithMixedCases.ProtobufOutput |
||||
Required.JsonInput.FieldNameWithMixedCases.Validator |
||||
Required.JsonInput.FieldNameWithNumbers.JsonOutput |
||||
Required.JsonInput.FieldNameWithNumbers.ProtobufOutput |
||||
Required.JsonInput.FieldNameWithNumbers.Validator |
||||
Required.JsonInput.FloatFieldInfinity.JsonOutput |
||||
Required.JsonInput.FloatFieldInfinity.ProtobufOutput |
||||
Required.JsonInput.FloatFieldMaxNegativeValue.JsonOutput |
||||
Required.JsonInput.FloatFieldMaxNegativeValue.ProtobufOutput |
||||
Required.JsonInput.FloatFieldMaxPositiveValue.JsonOutput |
||||
Required.JsonInput.FloatFieldMaxPositiveValue.ProtobufOutput |
||||
Required.JsonInput.FloatFieldMinNegativeValue.JsonOutput |
||||
Required.JsonInput.FloatFieldMinNegativeValue.ProtobufOutput |
||||
Required.JsonInput.FloatFieldMinPositiveValue.JsonOutput |
||||
Required.JsonInput.FloatFieldMinPositiveValue.ProtobufOutput |
||||
Required.JsonInput.FloatFieldNan.JsonOutput |
||||
Required.JsonInput.FloatFieldNan.ProtobufOutput |
||||
Required.JsonInput.FloatFieldNegativeInfinity.JsonOutput |
||||
Required.JsonInput.FloatFieldNegativeInfinity.ProtobufOutput |
||||
Required.JsonInput.FloatFieldQuotedValue.JsonOutput |
||||
Required.JsonInput.FloatFieldQuotedValue.ProtobufOutput |
||||
Required.JsonInput.FloatFieldTooLarge |
||||
Required.JsonInput.FloatFieldTooSmall |
||||
Required.JsonInput.HelloWorld.JsonOutput |
||||
Required.JsonInput.HelloWorld.ProtobufOutput |
||||
Required.JsonInput.Int32FieldExponentialFormat.JsonOutput |
||||
Required.JsonInput.Int32FieldExponentialFormat.ProtobufOutput |
||||
Required.JsonInput.Int32FieldFloatTrailingZero.JsonOutput |
||||
Required.JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput |
||||
Required.JsonInput.Int32FieldLeadingSpace |
||||
Required.JsonInput.Int32FieldLeadingZero |
||||
Required.JsonInput.Int32FieldMaxFloatValue.JsonOutput |
||||
Required.JsonInput.Int32FieldMaxFloatValue.ProtobufOutput |
||||
Required.JsonInput.Int32FieldMaxValue.JsonOutput |
||||
Required.JsonInput.Int32FieldMaxValue.ProtobufOutput |
||||
Required.JsonInput.Int32FieldMinFloatValue.JsonOutput |
||||
Required.JsonInput.Int32FieldMinFloatValue.ProtobufOutput |
||||
Required.JsonInput.Int32FieldMinValue.JsonOutput |
||||
Required.JsonInput.Int32FieldMinValue.ProtobufOutput |
||||
Required.JsonInput.Int32FieldNegativeWithLeadingZero |
||||
Required.JsonInput.Int32FieldNotInteger |
||||
Required.JsonInput.Int32FieldNotNumber |
||||
Required.JsonInput.Int32FieldPlusSign |
||||
Required.JsonInput.Int32FieldStringValue.JsonOutput |
||||
Required.JsonInput.Int32FieldStringValue.ProtobufOutput |
||||
Required.JsonInput.Int32FieldStringValueEscaped.JsonOutput |
||||
Required.JsonInput.Int32FieldStringValueEscaped.ProtobufOutput |
||||
Required.JsonInput.Int32FieldTooLarge |
||||
Required.JsonInput.Int32FieldTooSmall |
||||
Required.JsonInput.Int32FieldTrailingSpace |
||||
Required.JsonInput.Int32MapEscapedKey.JsonOutput |
||||
Required.JsonInput.Int32MapEscapedKey.ProtobufOutput |
||||
Required.JsonInput.Int32MapField.JsonOutput |
||||
Required.JsonInput.Int32MapField.ProtobufOutput |
||||
Required.JsonInput.Int64FieldMaxValue.JsonOutput |
||||
Required.JsonInput.Int64FieldMaxValue.ProtobufOutput |
||||
Required.JsonInput.Int64FieldMaxValueNotQuoted.JsonOutput |
||||
Required.JsonInput.Int64FieldMaxValueNotQuoted.ProtobufOutput |
||||
Required.JsonInput.Int64FieldMinValue.JsonOutput |
||||
Required.JsonInput.Int64FieldMinValue.ProtobufOutput |
||||
Required.JsonInput.Int64FieldMinValueNotQuoted.JsonOutput |
||||
Required.JsonInput.Int64FieldMinValueNotQuoted.ProtobufOutput |
||||
Required.JsonInput.Int64FieldNotInteger |
||||
Required.JsonInput.Int64FieldNotNumber |
||||
Required.JsonInput.Int64FieldTooLarge |
||||
Required.JsonInput.Int64FieldTooSmall |
||||
Required.JsonInput.Int64MapEscapedKey.JsonOutput |
||||
Required.JsonInput.Int64MapEscapedKey.ProtobufOutput |
||||
Required.JsonInput.Int64MapField.JsonOutput |
||||
Required.JsonInput.Int64MapField.ProtobufOutput |
||||
Required.JsonInput.MessageField.JsonOutput |
||||
Required.JsonInput.MessageField.ProtobufOutput |
||||
Required.JsonInput.MessageMapField.JsonOutput |
||||
Required.JsonInput.MessageMapField.ProtobufOutput |
||||
Required.JsonInput.MessageRepeatedField.JsonOutput |
||||
Required.JsonInput.MessageRepeatedField.ProtobufOutput |
||||
Required.JsonInput.OneofFieldDuplicate |
||||
Required.JsonInput.OptionalBoolWrapper.JsonOutput |
||||
Required.JsonInput.OptionalBoolWrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalBytesWrapper.JsonOutput |
||||
Required.JsonInput.OptionalBytesWrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalDoubleWrapper.JsonOutput |
||||
Required.JsonInput.OptionalDoubleWrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalFloatWrapper.JsonOutput |
||||
Required.JsonInput.OptionalFloatWrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalInt32Wrapper.JsonOutput |
||||
Required.JsonInput.OptionalInt32Wrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalInt64Wrapper.JsonOutput |
||||
Required.JsonInput.OptionalInt64Wrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalStringWrapper.JsonOutput |
||||
Required.JsonInput.OptionalStringWrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalUint32Wrapper.JsonOutput |
||||
Required.JsonInput.OptionalUint32Wrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalUint64Wrapper.JsonOutput |
||||
Required.JsonInput.OptionalUint64Wrapper.ProtobufOutput |
||||
Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput |
||||
Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput |
||||
Required.JsonInput.OriginalProtoFieldName.JsonOutput |
||||
Required.JsonInput.OriginalProtoFieldName.ProtobufOutput |
||||
Required.JsonInput.PrimitiveRepeatedField.JsonOutput |
||||
Required.JsonInput.PrimitiveRepeatedField.ProtobufOutput |
||||
Required.JsonInput.RepeatedBoolWrapper.JsonOutput |
||||
Required.JsonInput.RepeatedBoolWrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedBytesWrapper.JsonOutput |
||||
Required.JsonInput.RepeatedBytesWrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedDoubleWrapper.JsonOutput |
||||
Required.JsonInput.RepeatedDoubleWrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotMessage |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotString |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotBool |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotInt |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotString |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt |
||||
Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotMessage |
||||
Required.JsonInput.RepeatedFloatWrapper.JsonOutput |
||||
Required.JsonInput.RepeatedFloatWrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedInt32Wrapper.JsonOutput |
||||
Required.JsonInput.RepeatedInt32Wrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedInt64Wrapper.JsonOutput |
||||
Required.JsonInput.RepeatedInt64Wrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedStringWrapper.JsonOutput |
||||
Required.JsonInput.RepeatedStringWrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedUint32Wrapper.JsonOutput |
||||
Required.JsonInput.RepeatedUint32Wrapper.ProtobufOutput |
||||
Required.JsonInput.RepeatedUint64Wrapper.JsonOutput |
||||
Required.JsonInput.RepeatedUint64Wrapper.ProtobufOutput |
||||
Required.JsonInput.StringField.JsonOutput |
||||
Required.JsonInput.StringField.ProtobufOutput |
||||
Required.JsonInput.StringFieldEscape.JsonOutput |
||||
Required.JsonInput.StringFieldEscape.ProtobufOutput |
||||
Required.JsonInput.StringFieldNotAString |
||||
Required.JsonInput.StringFieldSurrogatePair.JsonOutput |
||||
Required.JsonInput.StringFieldSurrogatePair.ProtobufOutput |
||||
Required.JsonInput.StringFieldUnicode.JsonOutput |
||||
Required.JsonInput.StringFieldUnicode.ProtobufOutput |
||||
Required.JsonInput.StringFieldUnicodeEscape.JsonOutput |
||||
Required.JsonInput.StringFieldUnicodeEscape.ProtobufOutput |
||||
Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput |
||||
Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput |
||||
Required.JsonInput.StringRepeatedField.JsonOutput |
||||
Required.JsonInput.StringRepeatedField.ProtobufOutput |
||||
Required.JsonInput.Struct.JsonOutput |
||||
Required.JsonInput.Struct.ProtobufOutput |
||||
Required.JsonInput.TimestampJsonInputLowercaseT |
||||
Required.JsonInput.TimestampJsonInputLowercaseZ |
||||
Required.JsonInput.TimestampJsonInputMissingT |
||||
Required.JsonInput.TimestampJsonInputMissingZ |
||||
Required.JsonInput.TimestampJsonInputTooLarge |
||||
Required.JsonInput.TimestampJsonInputTooSmall |
||||
Required.JsonInput.TimestampMaxValue.JsonOutput |
||||
Required.JsonInput.TimestampMaxValue.ProtobufOutput |
||||
Required.JsonInput.TimestampMinValue.JsonOutput |
||||
Required.JsonInput.TimestampMinValue.ProtobufOutput |
||||
Required.JsonInput.TimestampRepeatedValue.JsonOutput |
||||
Required.JsonInput.TimestampRepeatedValue.ProtobufOutput |
||||
Required.JsonInput.TimestampWithNegativeOffset.JsonOutput |
||||
Required.JsonInput.TimestampWithNegativeOffset.ProtobufOutput |
||||
Required.JsonInput.TimestampWithPositiveOffset.JsonOutput |
||||
Required.JsonInput.TimestampWithPositiveOffset.ProtobufOutput |
||||
Required.JsonInput.Uint32FieldMaxFloatValue.JsonOutput |
||||
Required.JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput |
||||
Required.JsonInput.Uint32FieldMaxValue.JsonOutput |
||||
Required.JsonInput.Uint32FieldMaxValue.ProtobufOutput |
||||
Required.JsonInput.Uint32FieldNotInteger |
||||
Required.JsonInput.Uint32FieldNotNumber |
||||
Required.JsonInput.Uint32FieldTooLarge |
||||
Required.JsonInput.Uint32MapField.JsonOutput |
||||
Required.JsonInput.Uint32MapField.ProtobufOutput |
||||
Required.JsonInput.Uint64FieldMaxValue.JsonOutput |
||||
Required.JsonInput.Uint64FieldMaxValue.ProtobufOutput |
||||
Required.JsonInput.Uint64FieldMaxValueNotQuoted.JsonOutput |
||||
Required.JsonInput.Uint64FieldMaxValueNotQuoted.ProtobufOutput |
||||
Required.JsonInput.Uint64FieldNotInteger |
||||
Required.JsonInput.Uint64FieldNotNumber |
||||
Required.JsonInput.Uint64FieldTooLarge |
||||
Required.JsonInput.Uint64MapField.JsonOutput |
||||
Required.JsonInput.Uint64MapField.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptBool.JsonOutput |
||||
Required.JsonInput.ValueAcceptBool.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptFloat.JsonOutput |
||||
Required.JsonInput.ValueAcceptFloat.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptInteger.JsonOutput |
||||
Required.JsonInput.ValueAcceptInteger.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptList.JsonOutput |
||||
Required.JsonInput.ValueAcceptList.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptNull.JsonOutput |
||||
Required.JsonInput.ValueAcceptNull.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptObject.JsonOutput |
||||
Required.JsonInput.ValueAcceptObject.ProtobufOutput |
||||
Required.JsonInput.ValueAcceptString.JsonOutput |
||||
Required.JsonInput.ValueAcceptString.ProtobufOutput |
||||
Required.JsonInput.WrapperTypesWithNullValue.JsonOutput |
||||
Required.JsonInput.WrapperTypesWithNullValue.ProtobufOutput |
||||
Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput |
||||
Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput |
||||
Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput |
||||
Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput |
||||
Required.ProtobufInput.IllegalZeroFieldNum_Case_0 |
||||
Required.ProtobufInput.IllegalZeroFieldNum_Case_1 |
||||
Required.ProtobufInput.IllegalZeroFieldNum_Case_2 |
||||
Required.ProtobufInput.IllegalZeroFieldNum_Case_3 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.BOOL |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.BYTES |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.ENUM |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.INT32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.INT64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.STRING |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.UINT64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.BOOL |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.BYTES |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.ENUM |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.INT32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.INT64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.STRING |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.UINT64 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.BOOL |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.BYTES |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.ENUM |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.INT32 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.INT64 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.STRING |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofBeforeUnknownValue.UINT64 |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.BYTES |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.STRING |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.BYTES |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.STRING |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.BYTES |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.STRING |
||||
Required.ProtobufInput.PrematureEofInPackedField.BOOL |
||||
Required.ProtobufInput.PrematureEofInPackedField.DOUBLE |
||||
Required.ProtobufInput.PrematureEofInPackedField.ENUM |
||||
Required.ProtobufInput.PrematureEofInPackedField.FIXED32 |
||||
Required.ProtobufInput.PrematureEofInPackedField.FIXED64 |
||||
Required.ProtobufInput.PrematureEofInPackedField.FLOAT |
||||
Required.ProtobufInput.PrematureEofInPackedField.INT32 |
||||
Required.ProtobufInput.PrematureEofInPackedField.INT64 |
||||
Required.ProtobufInput.PrematureEofInPackedField.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofInPackedField.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofInPackedField.SINT32 |
||||
Required.ProtobufInput.PrematureEofInPackedField.SINT64 |
||||
Required.ProtobufInput.PrematureEofInPackedField.UINT32 |
||||
Required.ProtobufInput.PrematureEofInPackedField.UINT64 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.BOOL |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.ENUM |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.INT32 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.INT64 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofInPackedFieldValue.UINT64 |
||||
Required.ProtobufInput.PrematureEofInSubmessageValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.BOOL |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.BYTES |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.ENUM |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.INT32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.INT64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.STRING |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.UINT64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.BOOL |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.BYTES |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.ENUM |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.INT32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.INT64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.STRING |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.UINT64 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.BOOL |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.BYTES |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.DOUBLE |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.ENUM |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.FIXED32 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.FIXED64 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.FLOAT |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.INT32 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.INT64 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.MESSAGE |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.SFIXED32 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.SFIXED64 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.SINT32 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.SINT64 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.STRING |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.UINT32 |
||||
Required.ProtobufInput.PrematureEofInsideUnknownValue.UINT64 |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.BOOL.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.INT64.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SINT32.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.SINT64.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput |
||||
Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.BOOL.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.DOUBLE.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.DOUBLE.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.FIXED32.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.FIXED32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.FIXED64.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.FIXED64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.FLOAT.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.INT32.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.INT64.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.INT64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SFIXED32.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SFIXED32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SFIXED64.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SFIXED64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SINT32.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SINT64.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.UINT32.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataRepeated.UINT64.JsonOutput |
||||
Required.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.BOOL.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.BOOL.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.DOUBLE.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.DOUBLE.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.FIXED32.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.FIXED32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.FIXED64.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.FIXED64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.FLOAT.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.FLOAT.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.INT32.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.INT32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.INT64.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.INT64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.SFIXED32.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.SFIXED32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.SFIXED64.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.SFIXED64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.SINT32.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.SINT32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.SINT64.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.SINT64.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.UINT32.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.UINT32.ProtobufOutput |
||||
Required.ProtobufInput.ValidDataScalar.UINT64.JsonOutput |
||||
Required.ProtobufInput.ValidDataScalar.UINT64.ProtobufOutput |
||||
Required.TimestampProtoInputTooLarge.JsonOutput |
||||
Required.TimestampProtoInputTooSmall.JsonOutput |
||||
|
@ -0,0 +1,71 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.protobuf; |
||||
|
||||
/** |
||||
* Parsers to discard unknown fields during parsing. |
||||
*/ |
||||
public final class DiscardUnknownFieldsParser { |
||||
|
||||
/** |
||||
* Warps a given {@link Parser} into a new {@link Parser} that discards unknown fields during |
||||
* parsing. |
||||
* |
||||
* <p>Usage example: |
||||
* <pre>{@code |
||||
* private final static Parser<Foo> FOO_PARSER = DiscardUnknownFieldsParser.wrap(Foo.parser()); |
||||
* Foo parseFooDiscardUnknown(ByteBuffer input) throws IOException { |
||||
* return FOO_PARSER.parseFrom(input); |
||||
* } |
||||
* }</pre> |
||||
* |
||||
* <p>Like all other implementations of {@code Parser}, this parser is stateless and thread-safe. |
||||
* |
||||
* @param parser The delegated parser that parses messages. |
||||
* @return a {@link Parser} that will discard unknown fields during parsing. |
||||
*/ |
||||
public static final <T extends Message> Parser<T> wrap(final Parser<T> parser) { |
||||
return new AbstractParser<T>() { |
||||
@Override |
||||
public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) |
||||
throws InvalidProtocolBufferException { |
||||
try { |
||||
input.discardUnknownFields(); |
||||
return parser.parsePartialFrom(input, extensionRegistry); |
||||
} finally { |
||||
input.unsetDiscardUnknownFields(); |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
private DiscardUnknownFieldsParser() {} |
||||
} |
@ -0,0 +1,157 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.protobuf; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import protobuf_unittest.UnittestProto; |
||||
import proto3_unittest.UnittestProto3; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.junit.runners.JUnit4; |
||||
|
||||
/** Unit tests for discard or preserve unknown fields. */ |
||||
@RunWith(JUnit4.class) |
||||
public class DiscardUnknownFieldsTest { |
||||
@Test |
||||
public void testProto2() throws Exception { |
||||
testProto2Message( |
||||
UnittestProto.TestEmptyMessage.getDefaultInstance()); |
||||
testProto2Message( |
||||
UnittestProto.TestEmptyMessageWithExtensions.getDefaultInstance()); |
||||
testProto2Message( |
||||
DynamicMessage.getDefaultInstance(UnittestProto.TestEmptyMessage.getDescriptor())); |
||||
testProto2Message( |
||||
DynamicMessage.getDefaultInstance( |
||||
UnittestProto.TestEmptyMessageWithExtensions.getDescriptor())); |
||||
} |
||||
|
||||
@Test |
||||
public void testProto3() throws Exception { |
||||
testProto3Message(UnittestProto3.TestEmptyMessage.getDefaultInstance()); |
||||
testProto3Message( |
||||
DynamicMessage.getDefaultInstance(UnittestProto3.TestEmptyMessage.getDescriptor())); |
||||
} |
||||
|
||||
private static void testProto2Message(Message message) throws Exception { |
||||
assertUnknownFieldsDefaultPreserved(message); |
||||
assertUnknownFieldsExplicitlyDiscarded(message); |
||||
assertReuseCodedInputStreamPreserve(message); |
||||
assertUnknownFieldsInUnknownFieldSetArePreserve(message); |
||||
} |
||||
|
||||
private static void testProto3Message(Message message) throws Exception { |
||||
CodedInputStream.setProto3KeepUnknownsByDefaultForTest(); |
||||
assertUnknownFieldsDefaultPreserved(message); |
||||
assertUnknownFieldsExplicitlyDiscarded(message); |
||||
assertReuseCodedInputStreamPreserve(message); |
||||
assertUnknownFieldsInUnknownFieldSetArePreserve(message); |
||||
CodedInputStream.setProto3DiscardUnknownsByDefaultForTest(); |
||||
assertUnknownFieldsDefaultDiscarded(message); |
||||
assertUnknownFieldsExplicitlyDiscarded(message); |
||||
assertUnknownFieldsInUnknownFieldSetAreDiscarded(message); |
||||
} |
||||
|
||||
private static void assertReuseCodedInputStreamPreserve(Message message) throws Exception { |
||||
final int messageSize = payload.size(); |
||||
byte[] copied = new byte[messageSize * 2]; |
||||
payload.copyTo(copied, 0); |
||||
payload.copyTo(copied, messageSize); |
||||
CodedInputStream input = CodedInputStream.newInstance(copied); |
||||
{ |
||||
// Use DiscardUnknownFieldsParser to parse the first payload.
|
||||
int oldLimit = input.pushLimit(messageSize); |
||||
Message parsed = DiscardUnknownFieldsParser.wrap(message.getParserForType()).parseFrom(input); |
||||
assertEquals(message.getClass().getName(), 0, parsed.getSerializedSize()); |
||||
input.popLimit(oldLimit); |
||||
} |
||||
{ |
||||
// Use the normal parser to parse the remaining payload should have unknown fields preserved.
|
||||
Message parsed = message.getParserForType().parseFrom(input); |
||||
assertEquals(message.getClass().getName(), payload, parsed.toByteString()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* {@link Message.Builder#setUnknownFields(UnknownFieldSet)} and {@link |
||||
* Message.Builder#mergeUnknownFields(UnknownFieldSet)} should preserve the unknown fields. |
||||
*/ |
||||
private static void assertUnknownFieldsInUnknownFieldSetArePreserve(Message message) |
||||
throws Exception { |
||||
UnknownFieldSet unknownFields = UnknownFieldSet.newBuilder().mergeFrom(payload).build(); |
||||
Message built = message.newBuilderForType().setUnknownFields(unknownFields).build(); |
||||
assertEquals(message.getClass().getName(), payload, built.toByteString()); |
||||
|
||||
} |
||||
/** |
||||
* {@link Message.Builder#setUnknownFields(UnknownFieldSet)} and {@link |
||||
* Message.Builder#mergeUnknownFields(UnknownFieldSet)} should discard the unknown fields. |
||||
*/ |
||||
private static void assertUnknownFieldsInUnknownFieldSetAreDiscarded(Message message) |
||||
throws Exception { |
||||
UnknownFieldSet unknownFields = UnknownFieldSet.newBuilder().mergeFrom(payload).build(); |
||||
Message built = message.newBuilderForType().setUnknownFields(unknownFields).build(); |
||||
assertEquals(message.getClass().getName(), 0, built.getSerializedSize()); |
||||
} |
||||
|
||||
private static void assertUnknownFieldsDefaultPreserved(MessageLite message) throws Exception { |
||||
{ |
||||
MessageLite parsed = message.getParserForType().parseFrom(payload); |
||||
assertEquals(message.getClass().getName(), payload, parsed.toByteString()); |
||||
} |
||||
|
||||
{ |
||||
MessageLite parsed = message.newBuilderForType().mergeFrom(payload).build(); |
||||
assertEquals(message.getClass().getName(), payload, parsed.toByteString()); |
||||
} |
||||
} |
||||
|
||||
private static void assertUnknownFieldsDefaultDiscarded(MessageLite message) throws Exception { |
||||
{ |
||||
MessageLite parsed = message.getParserForType().parseFrom(payload); |
||||
assertEquals(message.getClass().getName(), 0, parsed.getSerializedSize()); |
||||
} |
||||
|
||||
{ |
||||
MessageLite parsed = message.newBuilderForType().mergeFrom(payload).build(); |
||||
assertEquals(message.getClass().getName(), 0, parsed.getSerializedSize()); |
||||
} |
||||
} |
||||
|
||||
private static void assertUnknownFieldsExplicitlyDiscarded(Message message) throws Exception { |
||||
Message parsed = |
||||
DiscardUnknownFieldsParser.wrap(message.getParserForType()).parseFrom(payload); |
||||
assertEquals(message.getClass().getName(), 0, parsed.getSerializedSize()); |
||||
} |
||||
|
||||
private static final ByteString payload = |
||||
TestUtilLite.getAllLiteSetBuilder().build().toByteString(); |
||||
} |
@ -0,0 +1,83 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.protobuf; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
/** |
||||
* Tests that proto2 api generation doesn't cause compile errors when compiling protocol buffers |
||||
* that have names that would otherwise conflict if not fully qualified (like @Deprecated |
||||
* and @Override). |
||||
* |
||||
* <p>Forked from {@link TestBadIdentifiers}. |
||||
* |
||||
* @author jonp@google.com (Jon Perlow) |
||||
*/ |
||||
public final class TestBadIdentifiersLite extends TestCase { |
||||
|
||||
public void testCompilation() { |
||||
// If this compiles, it means the generation was correct.
|
||||
TestBadIdentifiersProto.Deprecated.newBuilder(); |
||||
TestBadIdentifiersProto.Override.newBuilder(); |
||||
} |
||||
|
||||
public void testConflictingFieldNames() throws Exception { |
||||
TestBadIdentifiersProto.TestConflictingFieldNames message = |
||||
TestBadIdentifiersProto.TestConflictingFieldNames.getDefaultInstance(); |
||||
// Make sure generated accessors are properly named.
|
||||
assertEquals(0, message.getInt32Field1Count()); |
||||
assertEquals(0, message.getEnumField2Count()); |
||||
assertEquals(0, message.getStringField3Count()); |
||||
assertEquals(0, message.getBytesField4Count()); |
||||
assertEquals(0, message.getMessageField5Count()); |
||||
|
||||
assertEquals(0, message.getInt32FieldCount11()); |
||||
assertEquals(0, message.getEnumFieldCount12().getNumber()); |
||||
assertEquals("", message.getStringFieldCount13()); |
||||
assertEquals(ByteString.EMPTY, message.getBytesFieldCount14()); |
||||
assertEquals(0, message.getMessageFieldCount15().getSerializedSize()); |
||||
|
||||
assertEquals(0, message.getInt32Field21Count()); |
||||
assertEquals(0, message.getEnumField22Count()); |
||||
assertEquals(0, message.getStringField23Count()); |
||||
assertEquals(0, message.getBytesField24Count()); |
||||
assertEquals(0, message.getMessageField25Count()); |
||||
|
||||
assertEquals(0, message.getInt32Field1List().size()); |
||||
assertEquals(0, message.getInt32FieldList31()); |
||||
|
||||
assertEquals(0, message.getInt64FieldCount()); |
||||
assertEquals(0L, message.getExtension( |
||||
TestBadIdentifiersProto.TestConflictingFieldNames.int64FieldCount).longValue()); |
||||
assertEquals(0L, message.getExtension( |
||||
TestBadIdentifiersProto.TestConflictingFieldNames.int64FieldList).longValue()); |
||||
} |
||||
} |
@ -0,0 +1,355 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/** |
||||
* @fileoverview Test cases for Int64-manipulation functions. |
||||
* |
||||
* Test suite is written using Jasmine -- see http://jasmine.github.io/
|
||||
* |
||||
* @author cfallin@google.com (Chris Fallin) |
||||
*/ |
||||
|
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('jspb.arith.Int64'); |
||||
goog.require('jspb.arith.UInt64'); |
||||
|
||||
|
||||
describe('binaryArithTest', function() { |
||||
/** |
||||
* Tests comparison operations. |
||||
*/ |
||||
it('testCompare', function() { |
||||
var a = new jspb.arith.UInt64(1234, 5678); |
||||
var b = new jspb.arith.UInt64(1234, 5678); |
||||
assertEquals(a.cmp(b), 0); |
||||
assertEquals(b.cmp(a), 0); |
||||
b.lo -= 1; |
||||
assertEquals(a.cmp(b), 1); |
||||
assertEquals(b.cmp(a), -1); |
||||
b.lo += 2; |
||||
assertEquals(a.cmp(b), -1); |
||||
assertEquals(b.cmp(a), 1); |
||||
b.lo = a.lo; |
||||
b.hi = a.hi - 1; |
||||
assertEquals(a.cmp(b), 1); |
||||
assertEquals(b.cmp(a), -1); |
||||
|
||||
assertEquals(a.zero(), false); |
||||
assertEquals(a.msb(), false); |
||||
assertEquals(a.lsb(), false); |
||||
a.hi = 0; |
||||
a.lo = 0; |
||||
assertEquals(a.zero(), true); |
||||
a.hi = 0x80000000; |
||||
assertEquals(a.zero(), false); |
||||
assertEquals(a.msb(), true); |
||||
a.lo = 0x00000001; |
||||
assertEquals(a.lsb(), true); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests shifts. |
||||
*/ |
||||
it('testShifts', function() { |
||||
var a = new jspb.arith.UInt64(1, 0); |
||||
assertEquals(a.lo, 1); |
||||
assertEquals(a.hi, 0); |
||||
var orig = a; |
||||
a = a.leftShift(); |
||||
assertEquals(orig.lo, 1); // original unmodified.
|
||||
assertEquals(orig.hi, 0); |
||||
assertEquals(a.lo, 2); |
||||
assertEquals(a.hi, 0); |
||||
a = a.leftShift(); |
||||
assertEquals(a.lo, 4); |
||||
assertEquals(a.hi, 0); |
||||
for (var i = 0; i < 29; i++) { |
||||
a = a.leftShift(); |
||||
} |
||||
assertEquals(a.lo, 0x80000000); |
||||
assertEquals(a.hi, 0); |
||||
a = a.leftShift(); |
||||
assertEquals(a.lo, 0); |
||||
assertEquals(a.hi, 1); |
||||
a = a.leftShift(); |
||||
assertEquals(a.lo, 0); |
||||
assertEquals(a.hi, 2); |
||||
a = a.rightShift(); |
||||
a = a.rightShift(); |
||||
assertEquals(a.lo, 0x80000000); |
||||
assertEquals(a.hi, 0); |
||||
a = a.rightShift(); |
||||
assertEquals(a.lo, 0x40000000); |
||||
assertEquals(a.hi, 0); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests additions. |
||||
*/ |
||||
it('testAdd', function() { |
||||
var a = new jspb.arith.UInt64(/* lo = */ 0x89abcdef, |
||||
/* hi = */ 0x01234567); |
||||
var b = new jspb.arith.UInt64(/* lo = */ 0xff52ab91, |
||||
/* hi = */ 0x92fa2123); |
||||
// Addition with carry.
|
||||
var c = a.add(b); |
||||
assertEquals(a.lo, 0x89abcdef); // originals unmodified.
|
||||
assertEquals(a.hi, 0x01234567); |
||||
assertEquals(b.lo, 0xff52ab91); |
||||
assertEquals(b.hi, 0x92fa2123); |
||||
assertEquals(c.lo, 0x88fe7980); |
||||
assertEquals(c.hi, 0x941d668b); |
||||
|
||||
// Simple addition without carry.
|
||||
a.lo = 2; |
||||
a.hi = 0; |
||||
b.lo = 3; |
||||
b.hi = 0; |
||||
c = a.add(b); |
||||
assertEquals(c.lo, 5); |
||||
assertEquals(c.hi, 0); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Test subtractions. |
||||
*/ |
||||
it('testSub', function() { |
||||
var kLength = 10; |
||||
var hiValues = [0x1682ef32, |
||||
0x583902f7, |
||||
0xb62f5955, |
||||
0x6ea99bbf, |
||||
0x25a39c20, |
||||
0x0700a08b, |
||||
0x00f7304d, |
||||
0x91a5b5af, |
||||
0x89077fd2, |
||||
0xe09e347c]; |
||||
var loValues = [0xe1538b18, |
||||
0xbeacd556, |
||||
0x74100758, |
||||
0x96e3cb26, |
||||
0x56c37c3f, |
||||
0xe00b3f7d, |
||||
0x859f25d7, |
||||
0xc2ee614a, |
||||
0xe1d21cd7, |
||||
0x30aae6a4]; |
||||
for (var i = 0; i < kLength; i++) { |
||||
for (var j = 0; j < kLength; j++) { |
||||
var a = new jspb.arith.UInt64(loValues[i], hiValues[j]); |
||||
var b = new jspb.arith.UInt64(loValues[j], hiValues[i]); |
||||
var c = a.add(b).sub(b); |
||||
assertEquals(c.hi, a.hi); |
||||
assertEquals(c.lo, a.lo); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests 32-by-32 multiplication. |
||||
*/ |
||||
it('testMul32x32', function() { |
||||
var testData = [ |
||||
// a b low(a*b) high(a*b)
|
||||
[0xc0abe2f8, 0x1607898a, 0x5de711b0, 0x109471b8], |
||||
[0x915eb3cb, 0x4fb66d0e, 0xbd0d441a, 0x2d43d0bc], |
||||
[0xfe4efe70, 0x80b48c37, 0xbcddea10, 0x7fdada0c], |
||||
[0xe222fd4a, 0xe43d524a, 0xd5e0eb64, 0xc99d549c], |
||||
[0xd171f469, 0xb94ebd01, 0x4be17969, 0x979bc4fa], |
||||
[0x829cc1df, 0xe2598b38, 0xf4157dc8, 0x737c12ad], |
||||
[0xf10c3767, 0x8382881e, 0x942b3612, 0x7bd428b8], |
||||
[0xb0f6dd24, 0x232597e1, 0x079c98a4, 0x184bbce7], |
||||
[0xfcdb05a7, 0x902f55bc, 0x636199a4, 0x8e69f412], |
||||
[0x0dd0bfa9, 0x916e27b1, 0x6e2542d9, 0x07d92e65] |
||||
]; |
||||
|
||||
for (var i = 0; i < testData.length; i++) { |
||||
var a = testData[i][0] >>> 0; |
||||
var b = testData[i][1] >>> 0; |
||||
var cLow = testData[i][2] >>> 0; |
||||
var cHigh = testData[i][3] >>> 0; |
||||
var c = jspb.arith.UInt64.mul32x32(a, b); |
||||
assertEquals(c.lo, cLow); |
||||
assertEquals(c.hi, cHigh); |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests 64-by-32 multiplication. |
||||
*/ |
||||
it('testMul', function() { |
||||
// 64x32 bits produces 96 bits of product. The multiplication function under
|
||||
// test truncates the top 32 bits, so we compare against a 64-bit expected
|
||||
// product.
|
||||
var testData = [ |
||||
// low(a) high(a) low(a*b) high(a*b)
|
||||
[0xec10955b, 0x360eb168, 0x4b7f3f5b, 0xbfcb7c59, 0x9517da5f], |
||||
[0x42b000fc, 0x9d101642, 0x6fa1ab72, 0x2584c438, 0x6a9e6d2b], |
||||
[0xf42d4fb4, 0xae366403, 0xa65a1000, 0x92434000, 0x1ff978df], |
||||
[0x17e2f56b, 0x25487693, 0xf13f98c7, 0x73794e2d, 0xa96b0c6a], |
||||
[0x492f241f, 0x76c0eb67, 0x7377ac44, 0xd4336c3c, 0xfc4b1ebe], |
||||
[0xd6b92321, 0xe184fa48, 0xd6e76904, 0x93141584, 0xcbf44da1], |
||||
[0x4bf007ea, 0x968c0a9e, 0xf5e4026a, 0x4fdb1ae4, 0x61b9fb7d], |
||||
[0x10a83be7, 0x2d685ba6, 0xc9e5fb7f, 0x2ad43499, 0x3742473d], |
||||
[0x2f261829, 0x1aca681a, 0x3d3494e3, 0x8213205b, 0x283719f8], |
||||
[0xe4f2ce21, 0x2e74b7bd, 0xd801b38b, 0xbc17feeb, 0xc6c44e0f] |
||||
]; |
||||
|
||||
for (var i = 0; i < testData.length; i++) { |
||||
var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); |
||||
var prod = a.mul(testData[i][2]); |
||||
assertEquals(prod.lo, testData[i][3]); |
||||
assertEquals(prod.hi, testData[i][4]); |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests 64-div-by-32 division. |
||||
*/ |
||||
it('testDiv', function() { |
||||
// Compute a/b, yielding quot = a/b and rem = a%b.
|
||||
var testData = [ |
||||
// --- divisors in (0, 2^32-1) to test full divisor range
|
||||
// low(a) high(a) b low(quot) high(quot) rem
|
||||
[0x712443f1, 0xe85cefcc, 0xc1a7050b, 0x332c79ad, 0x00000001, 0x92ffa882], |
||||
[0x11912915, 0xb2699eb5, 0x30467cbe, 0xb21b4be4, 0x00000003, 0x283465dd], |
||||
[0x0d917982, 0x201f2a6e, 0x3f35bf03, 0x8217c8e4, 0x00000000, 0x153402d6], |
||||
[0xa072c108, 0x74020c96, 0xc60568fd, 0x95f9613e, 0x00000000, 0x3f4676c2], |
||||
[0xd845d5d8, 0xcdd235c4, 0x20426475, 0x6154e78b, 0x00000006, 0x202fb751], |
||||
[0xa4dbf71f, 0x9e90465e, 0xf08e022f, 0xa8be947f, 0x00000000, 0xbe43b5ce], |
||||
[0x3dbe627f, 0xa791f4b9, 0x28a5bd89, 0x1f5dfe93, 0x00000004, 0x02bf9ed4], |
||||
[0x5c1c53ee, 0xccf5102e, 0x198576e7, 0x07e3ae31, 0x00000008, 0x02ea8fb7], |
||||
[0xfef1e581, 0x04714067, 0xca6540c1, 0x059e73ec, 0x00000000, 0x31658095], |
||||
[0x1e2dd90c, 0x13dd6667, 0x8b2184c3, 0x248d1a42, 0x00000000, 0x4ca6d0c6], |
||||
// --- divisors in (0, 2^16-1) to test larger quotient high-words
|
||||
// low(a) high(a) b low(quot) high(quot) rem
|
||||
[0x86722b47, 0x2cd57c9a, 0x00003123, 0x2ae41b7a, 0x0000e995, 0x00000f99], |
||||
[0x1dd7884c, 0xf5e839bc, 0x00009eeb, 0x5c886242, 0x00018c21, 0x000099b6], |
||||
[0x5c53d625, 0x899fc7e5, 0x000087d7, 0xd625007a, 0x0001035c, 0x000019af], |
||||
[0x6932d932, 0x9d0a5488, 0x000051fb, 0x9d976143, 0x0001ea63, 0x00004981], |
||||
[0x4d18bb85, 0x0c92fb31, 0x00001d9f, 0x03265ab4, 0x00006cac, 0x000001b9], |
||||
[0xbe756768, 0xdea67ccb, 0x00008a03, 0x58add442, 0x00019cff, 0x000056a2], |
||||
[0xe2466f9a, 0x2521f114, 0x0000c350, 0xa0c0860d, 0x000030ab, 0x0000a48a], |
||||
[0xf00ddad1, 0xe2f5446a, 0x00002cfc, 0x762697a6, 0x00050b96, 0x00000b69], |
||||
[0xa879152a, 0x0a70e0a5, 0x00007cdf, 0xb44151b3, 0x00001567, 0x0000363d], |
||||
[0x7179a74c, 0x46083fff, 0x0000253c, 0x4d39ba6e, 0x0001e17f, 0x00000f84] |
||||
]; |
||||
|
||||
for (var i = 0; i < testData.length; i++) { |
||||
var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); |
||||
var result = a.div(testData[i][2]); |
||||
var quotient = result[0]; |
||||
var remainder = result[1]; |
||||
assertEquals(quotient.lo, testData[i][3]); |
||||
assertEquals(quotient.hi, testData[i][4]); |
||||
assertEquals(remainder.lo, testData[i][5]); |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests .toString() and .fromString(). |
||||
*/ |
||||
it('testStrings', function() { |
||||
var testData = [ |
||||
[0x5e84c935, 0xcae33d0e, '14619595947299359029'], |
||||
[0x62b3b8b8, 0x93480544, '10612738313170434232'], |
||||
[0x319bfb13, 0xc01c4172, '13843011313344445203'], |
||||
[0x5b8a65fb, 0xa5885b31, '11927883880638080507'], |
||||
[0x6bdb80f1, 0xb0d1b16b, '12741159895737008369'], |
||||
[0x4b82b442, 0x2e0d8c97, '3318463081876730946'], |
||||
[0x780d5208, 0x7d76752c, '9040542135845999112'], |
||||
[0x2e46800f, 0x0993778d, '690026616168284175'], |
||||
[0xf00a7e32, 0xcd8e3931, '14811839111111540274'], |
||||
[0x1baeccd6, 0x923048c4, '10533999535534820566'], |
||||
[0x03669d29, 0xbff3ab72, '13831587386756603177'], |
||||
[0x2526073e, 0x01affc81, '121593346566522686'], |
||||
[0xc24244e0, 0xd7f40d0e, '15561076969511732448'], |
||||
[0xc56a341e, 0xa68b66a7, '12000798502816461854'], |
||||
[0x8738d64d, 0xbfe78604, '13828168534871037517'], |
||||
[0x5baff03b, 0xd7572aea, '15516918227177304123'], |
||||
[0x4a843d8a, 0x864e132b, '9677693725920476554'], |
||||
[0x25b4e94d, 0x22b54dc6, '2500990681505655117'], |
||||
[0x6bbe664b, 0x55a5cc0e, '6171563226690381387'], |
||||
[0xee916c81, 0xb00aabb3, '12685140089732426881'] |
||||
]; |
||||
|
||||
for (var i = 0; i < testData.length; i++) { |
||||
var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); |
||||
var roundtrip = jspb.arith.UInt64.fromString(a.toString()); |
||||
assertEquals(roundtrip.lo, a.lo); |
||||
assertEquals(roundtrip.hi, a.hi); |
||||
assertEquals(a.toString(), testData[i][2]); |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests signed Int64s. These are built on UInt64s, so we only need to test |
||||
* the explicit overrides: .toString() and .fromString(). |
||||
*/ |
||||
it('testSignedInt64', function() { |
||||
var testStrings = [ |
||||
'-7847499644178593666', |
||||
'3771946501229139523', |
||||
'2872856549054995060', |
||||
'-5780049594274350904', |
||||
'3383785956695105201', |
||||
'2973055184857072610', |
||||
'-3879428459215627206', |
||||
'4589812431064156631', |
||||
'8484075557333689940', |
||||
'1075325817098092407', |
||||
'-4346697501012292314', |
||||
'2488620459718316637', |
||||
'6112655187423520672', |
||||
'-3655278273928612104', |
||||
'3439154019435803196', |
||||
'1004112478843763757', |
||||
'-6587790776614368413', |
||||
'664320065099714586', |
||||
'4760412909973292912', |
||||
'-7911903989602274672' |
||||
]; |
||||
|
||||
for (var i = 0; i < testStrings.length; i++) { |
||||
var roundtrip = |
||||
jspb.arith.Int64.fromString(testStrings[i]).toString(); |
||||
assertEquals(roundtrip, testStrings[i]); |
||||
} |
||||
}); |
||||
}); |
@ -0,0 +1,334 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/** |
||||
* @fileoverview Test cases for jspb's binary protocol buffer decoder. |
||||
* |
||||
* There are two particular magic numbers that need to be pointed out - |
||||
* 2^64-1025 is the largest number representable as both a double and an |
||||
* unsigned 64-bit integer, and 2^63-513 is the largest number representable as |
||||
* both a double and a signed 64-bit integer. |
||||
* |
||||
* Test suite is written using Jasmine -- see http://jasmine.github.io/
|
||||
* |
||||
* @author aappleby@google.com (Austin Appleby) |
||||
*/ |
||||
|
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('jspb.BinaryConstants'); |
||||
goog.require('jspb.BinaryDecoder'); |
||||
goog.require('jspb.BinaryEncoder'); |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of unsigned types. |
||||
* @param {Function} readValue |
||||
* @param {Function} writeValue |
||||
* @param {number} epsilon |
||||
* @param {number} upperLimit |
||||
* @param {Function} filter |
||||
* @suppress {missingProperties|visibility} |
||||
*/ |
||||
function doTestUnsignedValue(readValue, |
||||
writeValue, epsilon, upperLimit, filter) { |
||||
var encoder = new jspb.BinaryEncoder(); |
||||
|
||||
// Encode zero and limits.
|
||||
writeValue.call(encoder, filter(0)); |
||||
writeValue.call(encoder, filter(epsilon)); |
||||
writeValue.call(encoder, filter(upperLimit)); |
||||
|
||||
// Encode positive values.
|
||||
for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { |
||||
writeValue.call(encoder, filter(cursor)); |
||||
} |
||||
|
||||
var decoder = jspb.BinaryDecoder.alloc(encoder.end()); |
||||
|
||||
// Check zero and limits.
|
||||
assertEquals(filter(0), readValue.call(decoder)); |
||||
assertEquals(filter(epsilon), readValue.call(decoder)); |
||||
assertEquals(filter(upperLimit), readValue.call(decoder)); |
||||
|
||||
// Check positive values.
|
||||
for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { |
||||
if (filter(cursor) != readValue.call(decoder)) throw 'fail!'; |
||||
} |
||||
|
||||
// Encoding values outside the valid range should assert.
|
||||
assertThrows(function() {writeValue.call(encoder, -1);}); |
||||
assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);}); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of signed types. |
||||
* @param {Function} readValue |
||||
* @param {Function} writeValue |
||||
* @param {number} epsilon |
||||
* @param {number} lowerLimit |
||||
* @param {number} upperLimit |
||||
* @param {Function} filter |
||||
* @suppress {missingProperties} |
||||
*/ |
||||
function doTestSignedValue(readValue, |
||||
writeValue, epsilon, lowerLimit, upperLimit, filter) { |
||||
var encoder = new jspb.BinaryEncoder(); |
||||
|
||||
// Encode zero and limits.
|
||||
writeValue.call(encoder, filter(lowerLimit)); |
||||
writeValue.call(encoder, filter(-epsilon)); |
||||
writeValue.call(encoder, filter(0)); |
||||
writeValue.call(encoder, filter(epsilon)); |
||||
writeValue.call(encoder, filter(upperLimit)); |
||||
|
||||
var inputValues = []; |
||||
|
||||
// Encode negative values.
|
||||
for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) { |
||||
var val = filter(cursor); |
||||
writeValue.call(encoder, val); |
||||
inputValues.push(val); |
||||
} |
||||
|
||||
// Encode positive values.
|
||||
for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { |
||||
var val = filter(cursor); |
||||
writeValue.call(encoder, val); |
||||
inputValues.push(val); |
||||
} |
||||
|
||||
var decoder = jspb.BinaryDecoder.alloc(encoder.end()); |
||||
|
||||
// Check zero and limits.
|
||||
assertEquals(filter(lowerLimit), readValue.call(decoder)); |
||||
assertEquals(filter(-epsilon), readValue.call(decoder)); |
||||
assertEquals(filter(0), readValue.call(decoder)); |
||||
assertEquals(filter(epsilon), readValue.call(decoder)); |
||||
assertEquals(filter(upperLimit), readValue.call(decoder)); |
||||
|
||||
// Verify decoded values.
|
||||
for (var i = 0; i < inputValues.length; i++) { |
||||
assertEquals(inputValues[i], readValue.call(decoder)); |
||||
} |
||||
|
||||
// Encoding values outside the valid range should assert.
|
||||
assertThrows(function() {writeValue.call(encoder, lowerLimit * 1.1);}); |
||||
assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);}); |
||||
} |
||||
|
||||
describe('binaryDecoderTest', function() { |
||||
/** |
||||
* Tests the decoder instance cache. |
||||
*/ |
||||
it('testInstanceCache', /** @suppress {visibility} */ function() { |
||||
// Empty the instance caches.
|
||||
jspb.BinaryDecoder.instanceCache_ = []; |
||||
|
||||
// Allocating and then freeing a decoder should put it in the instance
|
||||
// cache.
|
||||
jspb.BinaryDecoder.alloc().free(); |
||||
|
||||
assertEquals(1, jspb.BinaryDecoder.instanceCache_.length); |
||||
|
||||
// Allocating and then freeing three decoders should leave us with three in
|
||||
// the cache.
|
||||
|
||||
var decoder1 = jspb.BinaryDecoder.alloc(); |
||||
var decoder2 = jspb.BinaryDecoder.alloc(); |
||||
var decoder3 = jspb.BinaryDecoder.alloc(); |
||||
decoder1.free(); |
||||
decoder2.free(); |
||||
decoder3.free(); |
||||
|
||||
assertEquals(3, jspb.BinaryDecoder.instanceCache_.length); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests reading 64-bit integers as hash strings. |
||||
*/ |
||||
it('testHashStrings', function() { |
||||
var encoder = new jspb.BinaryEncoder(); |
||||
|
||||
var hashA = String.fromCharCode(0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00); |
||||
var hashB = String.fromCharCode(0x12, 0x34, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00); |
||||
var hashC = String.fromCharCode(0x12, 0x34, 0x56, 0x78, |
||||
0x87, 0x65, 0x43, 0x21); |
||||
var hashD = String.fromCharCode(0xFF, 0xFF, 0xFF, 0xFF, |
||||
0xFF, 0xFF, 0xFF, 0xFF); |
||||
|
||||
encoder.writeVarintHash64(hashA); |
||||
encoder.writeVarintHash64(hashB); |
||||
encoder.writeVarintHash64(hashC); |
||||
encoder.writeVarintHash64(hashD); |
||||
|
||||
encoder.writeFixedHash64(hashA); |
||||
encoder.writeFixedHash64(hashB); |
||||
encoder.writeFixedHash64(hashC); |
||||
encoder.writeFixedHash64(hashD); |
||||
|
||||
var decoder = jspb.BinaryDecoder.alloc(encoder.end()); |
||||
|
||||
assertEquals(hashA, decoder.readVarintHash64()); |
||||
assertEquals(hashB, decoder.readVarintHash64()); |
||||
assertEquals(hashC, decoder.readVarintHash64()); |
||||
assertEquals(hashD, decoder.readVarintHash64()); |
||||
|
||||
assertEquals(hashA, decoder.readFixedHash64()); |
||||
assertEquals(hashB, decoder.readFixedHash64()); |
||||
assertEquals(hashC, decoder.readFixedHash64()); |
||||
assertEquals(hashD, decoder.readFixedHash64()); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Verifies that misuse of the decoder class triggers assertions. |
||||
* @suppress {checkTypes|visibility} |
||||
*/ |
||||
it('testDecodeErrors', function() { |
||||
// Reading a value past the end of the stream should trigger an assertion.
|
||||
var decoder = jspb.BinaryDecoder.alloc([0, 1, 2]); |
||||
assertThrows(function() {decoder.readUint64()}); |
||||
|
||||
// Overlong varints should trigger assertions.
|
||||
decoder.setBlock([255, 255, 255, 255, 255, 255, |
||||
255, 255, 255, 255, 255, 0]); |
||||
assertThrows(function() {decoder.readUnsignedVarint64()}); |
||||
decoder.reset(); |
||||
assertThrows(function() {decoder.readSignedVarint64()}); |
||||
decoder.reset(); |
||||
assertThrows(function() {decoder.readZigzagVarint64()}); |
||||
|
||||
// Positive 32-bit varints encoded with 1 bits in positions 33 through 35
|
||||
// should trigger assertions.
|
||||
decoder.setBlock([255, 255, 255, 255, 0x1F]); |
||||
assertThrows(function() {decoder.readUnsignedVarint32()}); |
||||
|
||||
decoder.setBlock([255, 255, 255, 255, 0x2F]); |
||||
assertThrows(function() {decoder.readUnsignedVarint32()}); |
||||
|
||||
decoder.setBlock([255, 255, 255, 255, 0x4F]); |
||||
assertThrows(function() {decoder.readUnsignedVarint32()}); |
||||
|
||||
// Negative 32-bit varints encoded with non-1 bits in the high dword should
|
||||
// trigger assertions.
|
||||
decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); |
||||
assertThrows(function() {decoder.readUnsignedVarint32()}); |
||||
|
||||
decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); |
||||
assertThrows(function() {decoder.readUnsignedVarint32()}); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of unsigned integers. |
||||
*/ |
||||
it('testUnsignedIntegers', function() { |
||||
doTestUnsignedValue( |
||||
jspb.BinaryDecoder.prototype.readUint8, |
||||
jspb.BinaryEncoder.prototype.writeUint8, |
||||
1, 0xFF, Math.round); |
||||
|
||||
doTestUnsignedValue( |
||||
jspb.BinaryDecoder.prototype.readUint16, |
||||
jspb.BinaryEncoder.prototype.writeUint16, |
||||
1, 0xFFFF, Math.round); |
||||
|
||||
doTestUnsignedValue( |
||||
jspb.BinaryDecoder.prototype.readUint32, |
||||
jspb.BinaryEncoder.prototype.writeUint32, |
||||
1, 0xFFFFFFFF, Math.round); |
||||
|
||||
doTestUnsignedValue( |
||||
jspb.BinaryDecoder.prototype.readUint64, |
||||
jspb.BinaryEncoder.prototype.writeUint64, |
||||
1, Math.pow(2, 64) - 1025, Math.round); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of signed integers. |
||||
*/ |
||||
it('testSignedIntegers', function() { |
||||
doTestSignedValue( |
||||
jspb.BinaryDecoder.prototype.readInt8, |
||||
jspb.BinaryEncoder.prototype.writeInt8, |
||||
1, -0x80, 0x7F, Math.round); |
||||
|
||||
doTestSignedValue( |
||||
jspb.BinaryDecoder.prototype.readInt16, |
||||
jspb.BinaryEncoder.prototype.writeInt16, |
||||
1, -0x8000, 0x7FFF, Math.round); |
||||
|
||||
doTestSignedValue( |
||||
jspb.BinaryDecoder.prototype.readInt32, |
||||
jspb.BinaryEncoder.prototype.writeInt32, |
||||
1, -0x80000000, 0x7FFFFFFF, Math.round); |
||||
|
||||
doTestSignedValue( |
||||
jspb.BinaryDecoder.prototype.readInt64, |
||||
jspb.BinaryEncoder.prototype.writeInt64, |
||||
1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of floats. |
||||
*/ |
||||
it('testFloats', function() { |
||||
/** |
||||
* @param {number} x |
||||
* @return {number} |
||||
*/ |
||||
function truncate(x) { |
||||
var temp = new Float32Array(1); |
||||
temp[0] = x; |
||||
return temp[0]; |
||||
} |
||||
doTestSignedValue( |
||||
jspb.BinaryDecoder.prototype.readFloat, |
||||
jspb.BinaryEncoder.prototype.writeFloat, |
||||
jspb.BinaryConstants.FLOAT32_EPS, |
||||
-jspb.BinaryConstants.FLOAT32_MAX, |
||||
jspb.BinaryConstants.FLOAT32_MAX, |
||||
truncate); |
||||
|
||||
doTestSignedValue( |
||||
jspb.BinaryDecoder.prototype.readDouble, |
||||
jspb.BinaryEncoder.prototype.writeDouble, |
||||
jspb.BinaryConstants.FLOAT64_EPS * 10, |
||||
-jspb.BinaryConstants.FLOAT64_MAX, |
||||
jspb.BinaryConstants.FLOAT64_MAX, |
||||
function(x) { return x; }); |
||||
}); |
||||
}); |
@ -0,0 +1,628 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Test suite is written using Jasmine -- see http://jasmine.github.io/
|
||||
|
||||
goog.require('goog.crypt.base64'); |
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('jspb.Message'); |
||||
|
||||
// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.ExtendsWithMessage'); |
||||
goog.require('proto.jspb.test.ForeignEnum'); |
||||
goog.require('proto.jspb.test.ForeignMessage'); |
||||
goog.require('proto.jspb.test.TestAllTypes'); |
||||
goog.require('proto.jspb.test.TestExtendable'); |
||||
goog.require('proto.jspb.test.extendOptionalBool'); |
||||
goog.require('proto.jspb.test.extendOptionalBytes'); |
||||
goog.require('proto.jspb.test.extendOptionalDouble'); |
||||
goog.require('proto.jspb.test.extendOptionalFixed32'); |
||||
goog.require('proto.jspb.test.extendOptionalFixed64'); |
||||
goog.require('proto.jspb.test.extendOptionalFloat'); |
||||
goog.require('proto.jspb.test.extendOptionalForeignEnum'); |
||||
goog.require('proto.jspb.test.extendOptionalInt32'); |
||||
goog.require('proto.jspb.test.extendOptionalInt64'); |
||||
goog.require('proto.jspb.test.extendOptionalSfixed32'); |
||||
goog.require('proto.jspb.test.extendOptionalSfixed64'); |
||||
goog.require('proto.jspb.test.extendOptionalSint32'); |
||||
goog.require('proto.jspb.test.extendOptionalSint64'); |
||||
goog.require('proto.jspb.test.extendOptionalString'); |
||||
goog.require('proto.jspb.test.extendOptionalUint32'); |
||||
goog.require('proto.jspb.test.extendOptionalUint64'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedBoolList'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedDoubleList'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedFixed32List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedFixed64List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedFloatList'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedForeignEnumList'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedInt32List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedInt64List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedSfixed32List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedSfixed64List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedSint32List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedSint64List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedUint32List'); |
||||
goog.require('proto.jspb.test.extendPackedRepeatedUint64List'); |
||||
goog.require('proto.jspb.test.extendRepeatedBoolList'); |
||||
goog.require('proto.jspb.test.extendRepeatedBytesList'); |
||||
goog.require('proto.jspb.test.extendRepeatedDoubleList'); |
||||
goog.require('proto.jspb.test.extendRepeatedFixed32List'); |
||||
goog.require('proto.jspb.test.extendRepeatedFixed64List'); |
||||
goog.require('proto.jspb.test.extendRepeatedFloatList'); |
||||
goog.require('proto.jspb.test.extendRepeatedForeignEnumList'); |
||||
goog.require('proto.jspb.test.extendRepeatedInt32List'); |
||||
goog.require('proto.jspb.test.extendRepeatedInt64List'); |
||||
goog.require('proto.jspb.test.extendRepeatedSfixed32List'); |
||||
goog.require('proto.jspb.test.extendRepeatedSfixed64List'); |
||||
goog.require('proto.jspb.test.extendRepeatedSint32List'); |
||||
goog.require('proto.jspb.test.extendRepeatedSint64List'); |
||||
goog.require('proto.jspb.test.extendRepeatedStringList'); |
||||
goog.require('proto.jspb.test.extendRepeatedUint32List'); |
||||
goog.require('proto.jspb.test.extendRepeatedUint64List'); |
||||
|
||||
|
||||
var suite = {}; |
||||
|
||||
var BYTES = new Uint8Array([1, 2, 8, 9]); |
||||
|
||||
var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES); |
||||
|
||||
|
||||
/** |
||||
* Helper: fill all fields on a TestAllTypes message. |
||||
* @param {proto.jspb.test.TestAllTypes} msg |
||||
*/ |
||||
function fillAllFields(msg) { |
||||
msg.setOptionalInt32(-42); |
||||
// can be exactly represented by JS number (64-bit double, i.e., 52-bit
|
||||
// mantissa).
|
||||
msg.setOptionalInt64(-0x7fffffff00000000); |
||||
msg.setOptionalUint32(0x80000000); |
||||
msg.setOptionalUint64(0xf000000000000000); |
||||
msg.setOptionalSint32(-100); |
||||
msg.setOptionalSint64(-0x8000000000000000); |
||||
msg.setOptionalFixed32(1234); |
||||
msg.setOptionalFixed64(0x1234567800000000); |
||||
msg.setOptionalSfixed32(-1234); |
||||
msg.setOptionalSfixed64(-0x1234567800000000); |
||||
msg.setOptionalFloat(1.5); |
||||
msg.setOptionalDouble(-1.5); |
||||
msg.setOptionalBool(true); |
||||
msg.setOptionalString('hello world'); |
||||
msg.setOptionalBytes(BYTES); |
||||
msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup()); |
||||
msg.getOptionalGroup().setA(100); |
||||
var submsg = new proto.jspb.test.ForeignMessage(); |
||||
submsg.setC(16); |
||||
msg.setOptionalForeignMessage(submsg); |
||||
msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
||||
msg.setOneofString('oneof'); |
||||
|
||||
|
||||
msg.setRepeatedInt32List([-42]); |
||||
msg.setRepeatedInt64List([-0x7fffffff00000000]); |
||||
msg.setRepeatedUint32List([0x80000000]); |
||||
msg.setRepeatedUint64List([0xf000000000000000]); |
||||
msg.setRepeatedSint32List([-100]); |
||||
msg.setRepeatedSint64List([-0x8000000000000000]); |
||||
msg.setRepeatedFixed32List([1234]); |
||||
msg.setRepeatedFixed64List([0x1234567800000000]); |
||||
msg.setRepeatedSfixed32List([-1234]); |
||||
msg.setRepeatedSfixed64List([-0x1234567800000000]); |
||||
msg.setRepeatedFloatList([1.5]); |
||||
msg.setRepeatedDoubleList([-1.5]); |
||||
msg.setRepeatedBoolList([true]); |
||||
msg.setRepeatedStringList(['hello world']); |
||||
msg.setRepeatedBytesList([BYTES, BYTES]); |
||||
msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]); |
||||
msg.getRepeatedGroupList()[0].setA(100); |
||||
submsg = new proto.jspb.test.ForeignMessage(); |
||||
submsg.setC(1000); |
||||
msg.setRepeatedForeignMessageList([submsg]); |
||||
msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
||||
|
||||
msg.setPackedRepeatedInt32List([-42]); |
||||
msg.setPackedRepeatedInt64List([-0x7fffffff00000000]); |
||||
msg.setPackedRepeatedUint32List([0x80000000]); |
||||
msg.setPackedRepeatedUint64List([0xf000000000000000]); |
||||
msg.setPackedRepeatedSint32List([-100]); |
||||
msg.setPackedRepeatedSint64List([-0x8000000000000000]); |
||||
msg.setPackedRepeatedFixed32List([1234]); |
||||
msg.setPackedRepeatedFixed64List([0x1234567800000000]); |
||||
msg.setPackedRepeatedSfixed32List([-1234]); |
||||
msg.setPackedRepeatedSfixed64List([-0x1234567800000000]); |
||||
msg.setPackedRepeatedFloatList([1.5]); |
||||
msg.setPackedRepeatedDoubleList([-1.5]); |
||||
msg.setPackedRepeatedBoolList([true]); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Helper: compare a bytes field to an expected value |
||||
* @param {Uint8Array|string} arr |
||||
* @param {Uint8Array} expected |
||||
* @return {boolean} |
||||
*/ |
||||
function bytesCompare(arr, expected) { |
||||
if (goog.isString(arr)) { |
||||
arr = goog.crypt.base64.decodeStringToUint8Array(arr); |
||||
} |
||||
if (arr.length != expected.length) { |
||||
return false; |
||||
} |
||||
for (var i = 0; i < arr.length; i++) { |
||||
if (arr[i] != expected[i]) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Helper: verify contents of given TestAllTypes message as set by |
||||
* fillAllFields(). |
||||
* @param {proto.jspb.test.TestAllTypes} original |
||||
* @param {proto.jspb.test.TestAllTypes} copy |
||||
*/ |
||||
function checkAllFields(original, copy) { |
||||
assertTrue(jspb.Message.equals(original, copy)); |
||||
|
||||
assertEquals(copy.getOptionalInt32(), -42); |
||||
assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000); |
||||
assertEquals(copy.getOptionalUint32(), 0x80000000); |
||||
assertEquals(copy.getOptionalUint64(), 0xf000000000000000); |
||||
assertEquals(copy.getOptionalSint32(), -100); |
||||
assertEquals(copy.getOptionalSint64(), -0x8000000000000000); |
||||
assertEquals(copy.getOptionalFixed32(), 1234); |
||||
assertEquals(copy.getOptionalFixed64(), 0x1234567800000000); |
||||
assertEquals(copy.getOptionalSfixed32(), -1234); |
||||
assertEquals(copy.getOptionalSfixed64(), -0x1234567800000000); |
||||
assertEquals(copy.getOptionalFloat(), 1.5); |
||||
assertEquals(copy.getOptionalDouble(), -1.5); |
||||
assertEquals(copy.getOptionalBool(), true); |
||||
assertEquals(copy.getOptionalString(), 'hello world'); |
||||
assertEquals(true, bytesCompare(copy.getOptionalBytes(), BYTES)); |
||||
assertEquals(true, bytesCompare(copy.getOptionalBytes_asU8(), BYTES)); |
||||
assertEquals( |
||||
copy.getOptionalBytes_asB64(), goog.crypt.base64.encodeByteArray(BYTES)); |
||||
|
||||
assertEquals(copy.getOptionalGroup().getA(), 100); |
||||
assertEquals(copy.getOptionalForeignMessage().getC(), 16); |
||||
assertEquals(copy.getOptionalForeignEnum(), |
||||
proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
||||
|
||||
|
||||
assertEquals(copy.getOneofString(), 'oneof'); |
||||
assertEquals(copy.getOneofFieldCase(), |
||||
proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING); |
||||
|
||||
assertElementsEquals(copy.getRepeatedInt32List(), [-42]); |
||||
assertElementsEquals(copy.getRepeatedInt64List(), [-0x7fffffff00000000]); |
||||
assertElementsEquals(copy.getRepeatedUint32List(), [0x80000000]); |
||||
assertElementsEquals(copy.getRepeatedUint64List(), [0xf000000000000000]); |
||||
assertElementsEquals(copy.getRepeatedSint32List(), [-100]); |
||||
assertElementsEquals(copy.getRepeatedSint64List(), [-0x8000000000000000]); |
||||
assertElementsEquals(copy.getRepeatedFixed32List(), [1234]); |
||||
assertElementsEquals(copy.getRepeatedFixed64List(), [0x1234567800000000]); |
||||
assertElementsEquals(copy.getRepeatedSfixed32List(), [-1234]); |
||||
assertElementsEquals(copy.getRepeatedSfixed64List(), [-0x1234567800000000]); |
||||
assertElementsEquals(copy.getRepeatedFloatList(), [1.5]); |
||||
assertElementsEquals(copy.getRepeatedDoubleList(), [-1.5]); |
||||
assertElementsEquals(copy.getRepeatedBoolList(), [true]); |
||||
assertElementsEquals(copy.getRepeatedStringList(), ['hello world']); |
||||
assertEquals(copy.getRepeatedBytesList().length, 2); |
||||
assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[0], BYTES)); |
||||
assertEquals(true, bytesCompare(copy.getRepeatedBytesList()[0], BYTES)); |
||||
assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[1], BYTES)); |
||||
assertEquals(copy.getRepeatedBytesList_asB64()[0], BYTES_B64); |
||||
assertEquals(copy.getRepeatedBytesList_asB64()[1], BYTES_B64); |
||||
assertEquals(copy.getRepeatedGroupList().length, 1); |
||||
assertEquals(copy.getRepeatedGroupList()[0].getA(), 100); |
||||
assertEquals(copy.getRepeatedForeignMessageList().length, 1); |
||||
assertEquals(copy.getRepeatedForeignMessageList()[0].getC(), 1000); |
||||
assertElementsEquals(copy.getRepeatedForeignEnumList(), |
||||
[proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
||||
|
||||
assertElementsEquals(copy.getPackedRepeatedInt32List(), [-42]); |
||||
assertElementsEquals(copy.getPackedRepeatedInt64List(), |
||||
[-0x7fffffff00000000]); |
||||
assertElementsEquals(copy.getPackedRepeatedUint32List(), [0x80000000]); |
||||
assertElementsEquals(copy.getPackedRepeatedUint64List(), |
||||
[0xf000000000000000]); |
||||
assertElementsEquals(copy.getPackedRepeatedSint32List(), [-100]); |
||||
assertElementsEquals(copy.getPackedRepeatedSint64List(), |
||||
[-0x8000000000000000]); |
||||
assertElementsEquals(copy.getPackedRepeatedFixed32List(), [1234]); |
||||
assertElementsEquals(copy.getPackedRepeatedFixed64List(), |
||||
[0x1234567800000000]); |
||||
assertElementsEquals(copy.getPackedRepeatedSfixed32List(), [-1234]); |
||||
assertElementsEquals(copy.getPackedRepeatedSfixed64List(), |
||||
[-0x1234567800000000]); |
||||
assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]); |
||||
assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Helper: verify that all expected extensions are present. |
||||
* @param {!proto.jspb.test.TestExtendable} msg |
||||
*/ |
||||
function checkExtensions(msg) { |
||||
assertEquals(-42, |
||||
msg.getExtension(proto.jspb.test.extendOptionalInt32)); |
||||
assertEquals(-0x7fffffff00000000, |
||||
msg.getExtension(proto.jspb.test.extendOptionalInt64)); |
||||
assertEquals(0x80000000, |
||||
msg.getExtension(proto.jspb.test.extendOptionalUint32)); |
||||
assertEquals(0xf000000000000000, |
||||
msg.getExtension(proto.jspb.test.extendOptionalUint64)); |
||||
assertEquals(-100, |
||||
msg.getExtension(proto.jspb.test.extendOptionalSint32)); |
||||
assertEquals(-0x8000000000000000, |
||||
msg.getExtension(proto.jspb.test.extendOptionalSint64)); |
||||
assertEquals(1234, |
||||
msg.getExtension(proto.jspb.test.extendOptionalFixed32)); |
||||
assertEquals(0x1234567800000000, |
||||
msg.getExtension(proto.jspb.test.extendOptionalFixed64)); |
||||
assertEquals(-1234, |
||||
msg.getExtension(proto.jspb.test.extendOptionalSfixed32)); |
||||
assertEquals(-0x1234567800000000, |
||||
msg.getExtension(proto.jspb.test.extendOptionalSfixed64)); |
||||
assertEquals(1.5, |
||||
msg.getExtension(proto.jspb.test.extendOptionalFloat)); |
||||
assertEquals(-1.5, |
||||
msg.getExtension(proto.jspb.test.extendOptionalDouble)); |
||||
assertEquals(true, |
||||
msg.getExtension(proto.jspb.test.extendOptionalBool)); |
||||
assertEquals('hello world', |
||||
msg.getExtension(proto.jspb.test.extendOptionalString)); |
||||
assertEquals( |
||||
true, bytesCompare( |
||||
msg.getExtension(proto.jspb.test.extendOptionalBytes), BYTES)); |
||||
assertEquals(16, |
||||
msg.getExtension( |
||||
proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo()); |
||||
|
||||
|
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedInt32List), |
||||
[-42]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedInt64List), |
||||
[-0x7fffffff00000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedUint32List), |
||||
[0x80000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedUint64List), |
||||
[0xf000000000000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedSint32List), |
||||
[-100]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedSint64List), |
||||
[-0x8000000000000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedFixed32List), |
||||
[1234]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedFixed64List), |
||||
[0x1234567800000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List), |
||||
[-1234]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List), |
||||
[-0x1234567800000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedFloatList), |
||||
[1.5]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedDoubleList), |
||||
[-1.5]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedBoolList), |
||||
[true]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedStringList), |
||||
['hello world']); |
||||
assertEquals( |
||||
true, |
||||
bytesCompare( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], BYTES)); |
||||
assertEquals(1000, |
||||
msg.getExtension( |
||||
proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0] |
||||
.getFoo()); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList), |
||||
[proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
||||
|
||||
|
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List), |
||||
[-42]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List), |
||||
[-0x7fffffff00000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List), |
||||
[0x80000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List), |
||||
[0xf000000000000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List), |
||||
[-100]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List), |
||||
[-0x8000000000000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List), |
||||
[1234]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List), |
||||
[0x1234567800000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List), |
||||
[-1234]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List), |
||||
[-0x1234567800000000]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList), |
||||
[1.5]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList), |
||||
[-1.5]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList), |
||||
[true]); |
||||
assertElementsEquals( |
||||
msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList), |
||||
[proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
||||
|
||||
} |
||||
|
||||
|
||||
describe('protoBinaryTest', function() { |
||||
/** |
||||
* Tests a basic serialization-deserializaton round-trip with all supported |
||||
* field types (on the TestAllTypes message type). |
||||
*/ |
||||
it('testRoundTrip', function() { |
||||
var msg = new proto.jspb.test.TestAllTypes(); |
||||
fillAllFields(msg); |
||||
var encoded = msg.serializeBinary(); |
||||
var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded); |
||||
checkAllFields(msg, decoded); |
||||
}); |
||||
|
||||
/** |
||||
* Test that base64 string and Uint8Array are interchangeable in bytes fields. |
||||
*/ |
||||
it('testBytesFieldsGettersInterop', function() { |
||||
var msg = new proto.jspb.test.TestAllTypes(); |
||||
// Set from a base64 string and check all the getters work.
|
||||
msg.setOptionalBytes(BYTES_B64); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
// Test binary serialize round trip doesn't break it.
|
||||
msg = proto.jspb.test.TestAllTypes.deserializeBinary(msg.serializeBinary()); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
msg = new proto.jspb.test.TestAllTypes(); |
||||
// Set from a Uint8Array and check all the getters work.
|
||||
msg.setOptionalBytes(BYTES); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
}); |
||||
|
||||
/** |
||||
* Test that bytes setters will receive result of any of the getters. |
||||
*/ |
||||
it('testBytesFieldsSettersInterop', function() { |
||||
var msg = new proto.jspb.test.TestAllTypes(); |
||||
msg.setOptionalBytes(BYTES); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
msg.setOptionalBytes(msg.getOptionalBytes()); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
msg.setOptionalBytes(msg.getOptionalBytes_asB64()); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
msg.setOptionalBytes(msg.getOptionalBytes_asU8()); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
}); |
||||
|
||||
/** |
||||
* Test that bytes setters will receive result of any of the getters. |
||||
*/ |
||||
it('testRepeatedBytesGetters', function() { |
||||
var msg = new proto.jspb.test.TestAllTypes(); |
||||
|
||||
function assertGetters() { |
||||
assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[0])); |
||||
assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[1])); |
||||
assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array); |
||||
assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array); |
||||
|
||||
assertTrue(bytesCompare(msg.getRepeatedBytesList()[0], BYTES)); |
||||
assertTrue(bytesCompare(msg.getRepeatedBytesList()[1], BYTES)); |
||||
assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[0], BYTES)); |
||||
assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[1], BYTES)); |
||||
assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[0], BYTES)); |
||||
assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[1], BYTES)); |
||||
} |
||||
|
||||
msg.setRepeatedBytesList([BYTES, BYTES]); |
||||
assertGetters(); |
||||
|
||||
msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]); |
||||
assertGetters(); |
||||
|
||||
msg.setRepeatedBytesList([]); |
||||
assertEquals(0, msg.getRepeatedBytesList().length); |
||||
assertEquals(0, msg.getRepeatedBytesList_asB64().length); |
||||
assertEquals(0, msg.getRepeatedBytesList_asU8().length); |
||||
}); |
||||
|
||||
/** |
||||
* Helper: fill all extension values. |
||||
* @param {proto.jspb.test.TestExtendable} msg |
||||
*/ |
||||
function fillExtensions(msg) { |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalInt32, -42); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalUint32, 0x80000000); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalUint64, 0xf000000000000000); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalSint32, -100); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalSint64, -0x8000000000000000); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalFixed32, 1234); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalFixed64, 0x1234567800000000); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalSfixed32, -1234); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalFloat, 1.5); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalDouble, -1.5); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalBool, true); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalString, 'hello world'); |
||||
msg.setExtension(proto.jspb.test.extendOptionalBytes, BYTES); |
||||
var submsg = new proto.jspb.test.ExtendsWithMessage(); |
||||
submsg.setFoo(16); |
||||
msg.setExtension( |
||||
proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendOptionalForeignEnum, |
||||
proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
||||
|
||||
|
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedInt32List, [-42]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedUint32List, [0x80000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedSint32List, [-100]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedFixed32List, [1234]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedSfixed32List, [-1234]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedFloatList, [1.5]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedDoubleList, [-1.5]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedBoolList, [true]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendRepeatedStringList, ['hello world']); |
||||
msg.setExtension(proto.jspb.test.extendRepeatedBytesList, [BYTES]); |
||||
submsg = new proto.jspb.test.ExtendsWithMessage(); |
||||
submsg.setFoo(1000); |
||||
msg.setExtension( |
||||
proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]); |
||||
msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList, |
||||
[proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
||||
|
||||
|
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedInt32List, [-42]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedSint32List, [-100]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedFixed32List, [1234]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedSfixed64List, |
||||
[-0x1234567800000000]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedFloatList, [1.5]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]); |
||||
msg.setExtension( |
||||
proto.jspb.test.extendPackedRepeatedBoolList, [true]); |
||||
msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList, |
||||
[proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* Tests extension serialization and deserialization. |
||||
*/ |
||||
it('testExtensions', function() { |
||||
var msg = new proto.jspb.test.TestExtendable(); |
||||
fillExtensions(msg); |
||||
var encoded = msg.serializeBinary(); |
||||
var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
||||
checkExtensions(decoded); |
||||
}); |
||||
}); |
@ -0,0 +1,922 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/** |
||||
* @fileoverview Test cases for jspb's binary protocol buffer reader. |
||||
* |
||||
* There are two particular magic numbers that need to be pointed out - |
||||
* 2^64-1025 is the largest number representable as both a double and an |
||||
* unsigned 64-bit integer, and 2^63-513 is the largest number representable as |
||||
* both a double and a signed 64-bit integer. |
||||
* |
||||
* Test suite is written using Jasmine -- see http://jasmine.github.io/
|
||||
* |
||||
* @author aappleby@google.com (Austin Appleby) |
||||
*/ |
||||
|
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('jspb.BinaryConstants'); |
||||
goog.require('jspb.BinaryDecoder'); |
||||
goog.require('jspb.BinaryReader'); |
||||
goog.require('jspb.BinaryWriter'); |
||||
|
||||
|
||||
|
||||
describe('binaryReaderTest', function() { |
||||
/** |
||||
* Tests the reader instance cache. |
||||
*/ |
||||
it('testInstanceCaches', /** @suppress {visibility} */ function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
writer.writeMessage(1, dummyMessage, goog.nullFunction); |
||||
writer.writeMessage(2, dummyMessage, goog.nullFunction); |
||||
|
||||
var buffer = writer.getResultBuffer(); |
||||
|
||||
// Empty the instance caches.
|
||||
jspb.BinaryReader.instanceCache_ = []; |
||||
|
||||
// Allocating and then freeing three decoders should leave us with three in
|
||||
// the cache.
|
||||
|
||||
var decoder1 = jspb.BinaryDecoder.alloc(); |
||||
var decoder2 = jspb.BinaryDecoder.alloc(); |
||||
var decoder3 = jspb.BinaryDecoder.alloc(); |
||||
decoder1.free(); |
||||
decoder2.free(); |
||||
decoder3.free(); |
||||
|
||||
assertEquals(3, jspb.BinaryDecoder.instanceCache_.length); |
||||
assertEquals(0, jspb.BinaryReader.instanceCache_.length); |
||||
|
||||
// Allocating and then freeing a reader should remove one decoder from its
|
||||
// cache, but it should stay stuck to the reader afterwards since we can't
|
||||
// have a reader without a decoder.
|
||||
jspb.BinaryReader.alloc().free(); |
||||
|
||||
assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); |
||||
assertEquals(1, jspb.BinaryReader.instanceCache_.length); |
||||
|
||||
// Allocating a reader should remove a reader from the cache.
|
||||
var reader = jspb.BinaryReader.alloc(buffer); |
||||
|
||||
assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); |
||||
assertEquals(0, jspb.BinaryReader.instanceCache_.length); |
||||
|
||||
// Processing the message reuses the current reader.
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
reader.readMessage(dummyMessage, function() { |
||||
assertEquals(0, jspb.BinaryReader.instanceCache_.length); |
||||
}); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
reader.readMessage(dummyMessage, function() { |
||||
assertEquals(0, jspb.BinaryReader.instanceCache_.length); |
||||
}); |
||||
|
||||
assertEquals(false, reader.nextField()); |
||||
|
||||
assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); |
||||
assertEquals(0, jspb.BinaryReader.instanceCache_.length); |
||||
|
||||
// Freeing the reader should put it back into the cache.
|
||||
reader.free(); |
||||
|
||||
assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); |
||||
assertEquals(1, jspb.BinaryReader.instanceCache_.length); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* @param {number} x |
||||
* @return {number} |
||||
*/ |
||||
function truncate(x) { |
||||
var temp = new Float32Array(1); |
||||
temp[0] = x; |
||||
return temp[0]; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Verifies that misuse of the reader class triggers assertions. |
||||
*/ |
||||
it('testReadErrors', /** @suppress {checkTypes|visibility} */ function() { |
||||
// Calling readMessage on a non-delimited field should trigger an
|
||||
// assertion.
|
||||
var reader = jspb.BinaryReader.alloc([8, 1]); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
reader.nextField(); |
||||
assertThrows(function() { |
||||
reader.readMessage(dummyMessage, goog.nullFunction); |
||||
}); |
||||
|
||||
// Reading past the end of the stream should trigger an assertion.
|
||||
reader = jspb.BinaryReader.alloc([9, 1]); |
||||
reader.nextField(); |
||||
assertThrows(function() {reader.readFixed64()}); |
||||
|
||||
// Reading past the end of a submessage should trigger an assertion.
|
||||
reader = jspb.BinaryReader.alloc([10, 4, 13, 1, 1, 1]); |
||||
reader.nextField(); |
||||
reader.readMessage(dummyMessage, function() { |
||||
reader.nextField(); |
||||
assertThrows(function() {reader.readFixed32()}); |
||||
}); |
||||
|
||||
// Skipping an invalid field should trigger an assertion.
|
||||
reader = jspb.BinaryReader.alloc([12, 1]); |
||||
reader.nextWireType_ = 1000; |
||||
assertThrows(function() {reader.skipField()}); |
||||
|
||||
// Reading fields with the wrong wire type should assert.
|
||||
reader = jspb.BinaryReader.alloc([9, 0, 0, 0, 0, 0, 0, 0, 0]); |
||||
reader.nextField(); |
||||
assertThrows(function() {reader.readInt32()}); |
||||
assertThrows(function() {reader.readInt32String()}); |
||||
assertThrows(function() {reader.readInt64()}); |
||||
assertThrows(function() {reader.readInt64String()}); |
||||
assertThrows(function() {reader.readUint32()}); |
||||
assertThrows(function() {reader.readUint32String()}); |
||||
assertThrows(function() {reader.readUint64()}); |
||||
assertThrows(function() {reader.readUint64String()}); |
||||
assertThrows(function() {reader.readSint32()}); |
||||
assertThrows(function() {reader.readBool()}); |
||||
assertThrows(function() {reader.readEnum()}); |
||||
|
||||
reader = jspb.BinaryReader.alloc([8, 1]); |
||||
reader.nextField(); |
||||
assertThrows(function() {reader.readFixed32()}); |
||||
assertThrows(function() {reader.readFixed64()}); |
||||
assertThrows(function() {reader.readSfixed32()}); |
||||
assertThrows(function() {reader.readSfixed64()}); |
||||
assertThrows(function() {reader.readFloat()}); |
||||
assertThrows(function() {reader.readDouble()}); |
||||
|
||||
assertThrows(function() {reader.readString()}); |
||||
assertThrows(function() {reader.readBytes()}); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of unsigned field types. |
||||
* @param {Function} readField |
||||
* @param {Function} writeField |
||||
* @param {number} epsilon |
||||
* @param {number} upperLimit |
||||
* @param {Function} filter |
||||
* @private |
||||
* @suppress {missingProperties} |
||||
*/ |
||||
var doTestUnsignedField_ = function(readField, |
||||
writeField, epsilon, upperLimit, filter) { |
||||
assertNotNull(readField); |
||||
assertNotNull(writeField); |
||||
|
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
// Encode zero and limits.
|
||||
writeField.call(writer, 1, filter(0)); |
||||
writeField.call(writer, 2, filter(epsilon)); |
||||
writeField.call(writer, 3, filter(upperLimit)); |
||||
|
||||
// Encode positive values.
|
||||
for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { |
||||
writeField.call(writer, 4, filter(cursor)); |
||||
} |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
// Check zero and limits.
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
assertEquals(filter(0), readField.call(reader)); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
assertEquals(filter(epsilon), readField.call(reader)); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(3, reader.getFieldNumber()); |
||||
assertEquals(filter(upperLimit), readField.call(reader)); |
||||
|
||||
// Check positive values.
|
||||
for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { |
||||
reader.nextField(); |
||||
if (4 != reader.getFieldNumber()) throw 'fail!'; |
||||
if (filter(cursor) != readField.call(reader)) throw 'fail!'; |
||||
} |
||||
}; |
||||
|
||||
|
||||
/** |
||||
* Tests encoding and decoding of signed field types. |
||||
* @param {Function} readField |
||||
* @param {Function} writeField |
||||
* @param {number} epsilon |
||||
* @param {number} lowerLimit |
||||
* @param {number} upperLimit |
||||
* @param {Function} filter |
||||
* @private |
||||
* @suppress {missingProperties} |
||||
*/ |
||||
var doTestSignedField_ = function(readField, |
||||
writeField, epsilon, lowerLimit, upperLimit, filter) { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
// Encode zero and limits.
|
||||
writeField.call(writer, 1, filter(lowerLimit)); |
||||
writeField.call(writer, 2, filter(-epsilon)); |
||||
writeField.call(writer, 3, filter(0)); |
||||
writeField.call(writer, 4, filter(epsilon)); |
||||
writeField.call(writer, 5, filter(upperLimit)); |
||||
|
||||
var inputValues = []; |
||||
|
||||
// Encode negative values.
|
||||
for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) { |
||||
var val = filter(cursor); |
||||
writeField.call(writer, 6, val); |
||||
inputValues.push({ |
||||
fieldNumber: 6, |
||||
value: val |
||||
}); |
||||
} |
||||
|
||||
// Encode positive values.
|
||||
for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { |
||||
var val = filter(cursor); |
||||
writeField.call(writer, 7, val); |
||||
inputValues.push({ |
||||
fieldNumber: 7, |
||||
value: val |
||||
}); |
||||
} |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
// Check zero and limits.
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
assertEquals(filter(lowerLimit), readField.call(reader)); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
assertEquals(filter(-epsilon), readField.call(reader)); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(3, reader.getFieldNumber()); |
||||
assertEquals(filter(0), readField.call(reader)); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(4, reader.getFieldNumber()); |
||||
assertEquals(filter(epsilon), readField.call(reader)); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(5, reader.getFieldNumber()); |
||||
assertEquals(filter(upperLimit), readField.call(reader)); |
||||
|
||||
for (var i = 0; i < inputValues.length; i++) { |
||||
var expected = inputValues[i]; |
||||
reader.nextField(); |
||||
assertEquals(expected.fieldNumber, reader.getFieldNumber()); |
||||
assertEquals(expected.value, readField.call(reader)); |
||||
} |
||||
}; |
||||
|
||||
|
||||
/** |
||||
* Tests fields that use varint encoding. |
||||
*/ |
||||
it('testVarintFields', function() { |
||||
assertNotUndefined(jspb.BinaryReader.prototype.readUint32); |
||||
assertNotUndefined(jspb.BinaryWriter.prototype.writeUint32); |
||||
assertNotUndefined(jspb.BinaryReader.prototype.readUint64); |
||||
assertNotUndefined(jspb.BinaryWriter.prototype.writeUint64); |
||||
assertNotUndefined(jspb.BinaryReader.prototype.readBool); |
||||
assertNotUndefined(jspb.BinaryWriter.prototype.writeBool); |
||||
doTestUnsignedField_( |
||||
jspb.BinaryReader.prototype.readUint32, |
||||
jspb.BinaryWriter.prototype.writeUint32, |
||||
1, Math.pow(2, 32) - 1, Math.round); |
||||
|
||||
doTestUnsignedField_( |
||||
jspb.BinaryReader.prototype.readUint64, |
||||
jspb.BinaryWriter.prototype.writeUint64, |
||||
1, Math.pow(2, 64) - 1025, Math.round); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readInt32, |
||||
jspb.BinaryWriter.prototype.writeInt32, |
||||
1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readInt64, |
||||
jspb.BinaryWriter.prototype.writeInt64, |
||||
1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readEnum, |
||||
jspb.BinaryWriter.prototype.writeEnum, |
||||
1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); |
||||
|
||||
doTestUnsignedField_( |
||||
jspb.BinaryReader.prototype.readBool, |
||||
jspb.BinaryWriter.prototype.writeBool, |
||||
1, 1, function(x) { return !!x; }); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests reading a field from hexadecimal string (format: '08 BE EF'). |
||||
* @param {Function} readField |
||||
* @param {number} expected |
||||
* @param {string} hexString |
||||
*/ |
||||
function doTestHexStringVarint_(readField, expected, hexString) { |
||||
var bytesCount = (hexString.length + 1) / 3; |
||||
var bytes = new Uint8Array(bytesCount); |
||||
for (var i = 0; i < bytesCount; i++) { |
||||
bytes[i] = parseInt(hexString.substring(i * 3, i * 3 + 2), 16); |
||||
} |
||||
var reader = jspb.BinaryReader.alloc(bytes); |
||||
reader.nextField(); |
||||
assertEquals(expected, readField.call(reader)); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Tests non-canonical redundant varint decoding. |
||||
*/ |
||||
it('testRedundantVarintFields', function() { |
||||
assertNotNull(jspb.BinaryReader.prototype.readUint32); |
||||
assertNotNull(jspb.BinaryReader.prototype.readUint64); |
||||
assertNotNull(jspb.BinaryReader.prototype.readSint32); |
||||
assertNotNull(jspb.BinaryReader.prototype.readSint64); |
||||
|
||||
// uint32 and sint32 take no more than 5 bytes
|
||||
// 08 - field prefix (type = 0 means varint)
|
||||
doTestHexStringVarint_( |
||||
jspb.BinaryReader.prototype.readUint32, |
||||
12, '08 8C 80 80 80 00'); |
||||
|
||||
// 11 stands for -6 in zigzag encoding
|
||||
doTestHexStringVarint_( |
||||
jspb.BinaryReader.prototype.readSint32, |
||||
-6, '08 8B 80 80 80 00'); |
||||
|
||||
// uint64 and sint64 take no more than 10 bytes
|
||||
// 08 - field prefix (type = 0 means varint)
|
||||
doTestHexStringVarint_( |
||||
jspb.BinaryReader.prototype.readUint64, |
||||
12, '08 8C 80 80 80 80 80 80 80 80 00'); |
||||
|
||||
// 11 stands for -6 in zigzag encoding
|
||||
doTestHexStringVarint_( |
||||
jspb.BinaryReader.prototype.readSint64, |
||||
-6, '08 8B 80 80 80 80 80 80 80 80 00'); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests 64-bit fields that are handled as strings. |
||||
*/ |
||||
it('testStringInt64Fields', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var testSignedData = [ |
||||
'2730538252207801776', |
||||
'-2688470994844604560', |
||||
'3398529779486536359', |
||||
'3568577411627971000', |
||||
'272477188847484900', |
||||
'-6649058714086158188', |
||||
'-7695254765712060806', |
||||
'-4525541438037104029', |
||||
'-4993706538836508568', |
||||
'4990160321893729138' |
||||
]; |
||||
var testUnsignedData = [ |
||||
'7822732630241694882', |
||||
'6753602971916687352', |
||||
'2399935075244442116', |
||||
'8724292567325338867', |
||||
'16948784802625696584', |
||||
'4136275908516066934', |
||||
'3575388346793700364', |
||||
'5167142028379259461', |
||||
'1557573948689737699', |
||||
'17100725280812548567' |
||||
]; |
||||
|
||||
for (var i = 0; i < testSignedData.length; i++) { |
||||
writer.writeInt64String(2 * i + 1, testSignedData[i]); |
||||
writer.writeUint64String(2 * i + 2, testUnsignedData[i]); |
||||
} |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
for (var i = 0; i < testSignedData.length; i++) { |
||||
reader.nextField(); |
||||
assertEquals(2 * i + 1, reader.getFieldNumber()); |
||||
assertEquals(testSignedData[i], reader.readInt64String()); |
||||
reader.nextField(); |
||||
assertEquals(2 * i + 2, reader.getFieldNumber()); |
||||
assertEquals(testUnsignedData[i], reader.readUint64String()); |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests fields that use zigzag encoding. |
||||
*/ |
||||
it('testZigzagFields', function() { |
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readSint32, |
||||
jspb.BinaryWriter.prototype.writeSint32, |
||||
1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readSint64, |
||||
jspb.BinaryWriter.prototype.writeSint64, |
||||
1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests fields that use fixed-length encoding. |
||||
*/ |
||||
it('testFixedFields', function() { |
||||
doTestUnsignedField_( |
||||
jspb.BinaryReader.prototype.readFixed32, |
||||
jspb.BinaryWriter.prototype.writeFixed32, |
||||
1, Math.pow(2, 32) - 1, Math.round); |
||||
|
||||
doTestUnsignedField_( |
||||
jspb.BinaryReader.prototype.readFixed64, |
||||
jspb.BinaryWriter.prototype.writeFixed64, |
||||
1, Math.pow(2, 64) - 1025, Math.round); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readSfixed32, |
||||
jspb.BinaryWriter.prototype.writeSfixed32, |
||||
1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readSfixed64, |
||||
jspb.BinaryWriter.prototype.writeSfixed64, |
||||
1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests floating point fields. |
||||
*/ |
||||
it('testFloatFields', function() { |
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readFloat, |
||||
jspb.BinaryWriter.prototype.writeFloat, |
||||
jspb.BinaryConstants.FLOAT32_MIN, |
||||
-jspb.BinaryConstants.FLOAT32_MAX, |
||||
jspb.BinaryConstants.FLOAT32_MAX, |
||||
truncate); |
||||
|
||||
doTestSignedField_( |
||||
jspb.BinaryReader.prototype.readDouble, |
||||
jspb.BinaryWriter.prototype.writeDouble, |
||||
jspb.BinaryConstants.FLOAT64_EPS * 10, |
||||
-jspb.BinaryConstants.FLOAT64_MIN, |
||||
jspb.BinaryConstants.FLOAT64_MIN, |
||||
function(x) { return x; }); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests length-delimited string fields. |
||||
*/ |
||||
it('testStringFields', function() { |
||||
var s1 = 'The quick brown fox jumps over the lazy dog.'; |
||||
var s2 = '人人生而自由,在尊嚴和權利上一律平等。'; |
||||
|
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
writer.writeString(1, s1); |
||||
writer.writeString(2, s2); |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
assertEquals(s1, reader.readString()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
assertEquals(s2, reader.readString()); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests length-delimited byte fields. |
||||
*/ |
||||
it('testByteFields', function() { |
||||
var message = []; |
||||
var lowerLimit = 1; |
||||
var upperLimit = 256; |
||||
var scale = 1.1; |
||||
|
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
for (var cursor = lowerLimit; cursor < upperLimit; cursor *= 1.1) { |
||||
var len = Math.round(cursor); |
||||
var bytes = []; |
||||
for (var i = 0; i < len; i++) bytes.push(i % 256); |
||||
|
||||
writer.writeBytes(len, bytes); |
||||
} |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
for (var cursor = lowerLimit; reader.nextField(); cursor *= 1.1) { |
||||
var len = Math.round(cursor); |
||||
if (len != reader.getFieldNumber()) throw 'fail!'; |
||||
|
||||
var bytes = reader.readBytes(); |
||||
if (len != bytes.length) throw 'fail!'; |
||||
for (var i = 0; i < bytes.length; i++) { |
||||
if (i % 256 != bytes[i]) throw 'fail!'; |
||||
} |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests nested messages. |
||||
*/ |
||||
it('testNesting', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
|
||||
writer.writeInt32(1, 100); |
||||
|
||||
// Add one message with 3 int fields.
|
||||
writer.writeMessage(2, dummyMessage, function() { |
||||
writer.writeInt32(3, 300); |
||||
writer.writeInt32(4, 400); |
||||
writer.writeInt32(5, 500); |
||||
}); |
||||
|
||||
// Add one empty message.
|
||||
writer.writeMessage(6, dummyMessage, goog.nullFunction); |
||||
|
||||
writer.writeInt32(7, 700); |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
// Validate outermost message.
|
||||
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
assertEquals(100, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
reader.readMessage(dummyMessage, function() { |
||||
// Validate embedded message 1.
|
||||
reader.nextField(); |
||||
assertEquals(3, reader.getFieldNumber()); |
||||
assertEquals(300, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(4, reader.getFieldNumber()); |
||||
assertEquals(400, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(5, reader.getFieldNumber()); |
||||
assertEquals(500, reader.readInt32()); |
||||
|
||||
assertEquals(false, reader.nextField()); |
||||
}); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(6, reader.getFieldNumber()); |
||||
reader.readMessage(dummyMessage, function() { |
||||
// Validate embedded message 2.
|
||||
|
||||
assertEquals(false, reader.nextField()); |
||||
}); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(7, reader.getFieldNumber()); |
||||
assertEquals(700, reader.readInt32()); |
||||
|
||||
assertEquals(false, reader.nextField()); |
||||
}); |
||||
|
||||
/** |
||||
* Tests skipping fields of each type by interleaving them with sentinel |
||||
* values and skipping everything that's not a sentinel. |
||||
*/ |
||||
it('testSkipField', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var sentinel = 123456789; |
||||
|
||||
// Write varint fields of different sizes.
|
||||
writer.writeInt32(1, sentinel); |
||||
writer.writeInt32(1, 1); |
||||
writer.writeInt32(1, 1000); |
||||
writer.writeInt32(1, 1000000); |
||||
writer.writeInt32(1, 1000000000); |
||||
|
||||
// Write fixed 64-bit encoded fields.
|
||||
writer.writeInt32(2, sentinel); |
||||
writer.writeDouble(2, 1); |
||||
writer.writeFixed64(2, 1); |
||||
writer.writeSfixed64(2, 1); |
||||
|
||||
// Write fixed 32-bit encoded fields.
|
||||
writer.writeInt32(3, sentinel); |
||||
writer.writeFloat(3, 1); |
||||
writer.writeFixed32(3, 1); |
||||
writer.writeSfixed32(3, 1); |
||||
|
||||
// Write delimited fields.
|
||||
writer.writeInt32(4, sentinel); |
||||
writer.writeBytes(4, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
||||
writer.writeString(4, 'The quick brown fox jumps over the lazy dog'); |
||||
|
||||
// Write a group with a nested group inside.
|
||||
writer.writeInt32(5, sentinel); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
writer.writeGroup(5, dummyMessage, function() { |
||||
writer.writeInt64(42, 42); |
||||
writer.writeGroup(6, dummyMessage, function() { |
||||
writer.writeInt64(84, 42); |
||||
}); |
||||
}); |
||||
|
||||
// Write final sentinel.
|
||||
writer.writeInt32(6, sentinel); |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
function skip(field, count) { |
||||
for (var i = 0; i < count; i++) { |
||||
reader.nextField(); |
||||
if (field != reader.getFieldNumber()) throw 'fail!'; |
||||
reader.skipField(); |
||||
} |
||||
} |
||||
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
skip(1, 4); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
skip(2, 3); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(3, reader.getFieldNumber()); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
skip(3, 3); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(4, reader.getFieldNumber()); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
skip(4, 2); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(5, reader.getFieldNumber()); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
skip(5, 1); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(6, reader.getFieldNumber()); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests packed fields. |
||||
*/ |
||||
it('testPackedFields', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var sentinel = 123456789; |
||||
|
||||
var unsignedData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
||||
var signedData = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]; |
||||
var floatData = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10]; |
||||
var doubleData = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10]; |
||||
var boolData = [true, false, true, true, false, false, true, false]; |
||||
|
||||
for (var i = 0; i < floatData.length; i++) { |
||||
floatData[i] = truncate(floatData[i]); |
||||
} |
||||
|
||||
writer.writeInt32(1, sentinel); |
||||
|
||||
writer.writePackedInt32(2, signedData); |
||||
writer.writePackedInt64(2, signedData); |
||||
writer.writePackedUint32(2, unsignedData); |
||||
writer.writePackedUint64(2, unsignedData); |
||||
writer.writePackedSint32(2, signedData); |
||||
writer.writePackedSint64(2, signedData); |
||||
writer.writePackedFixed32(2, unsignedData); |
||||
writer.writePackedFixed64(2, unsignedData); |
||||
writer.writePackedSfixed32(2, signedData); |
||||
writer.writePackedSfixed64(2, signedData); |
||||
writer.writePackedFloat(2, floatData); |
||||
writer.writePackedDouble(2, doubleData); |
||||
writer.writePackedBool(2, boolData); |
||||
writer.writePackedEnum(2, unsignedData); |
||||
|
||||
writer.writeInt32(3, sentinel); |
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedInt32(), signedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedInt64(), signedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedUint32(), unsignedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedUint64(), unsignedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedSint32(), signedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedSint64(), signedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedFixed32(), unsignedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedFixed64(), unsignedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedSfixed32(), signedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedSfixed64(), signedData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedFloat(), floatData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedDouble(), doubleData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedBool(), boolData); |
||||
|
||||
reader.nextField(); |
||||
assertElementsEquals(reader.readPackedEnum(), unsignedData); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(sentinel, reader.readInt32()); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Byte blobs inside nested messages should always have their byte offset set |
||||
* relative to the start of the outermost blob, not the start of their parent |
||||
* blob. |
||||
*/ |
||||
it('testNestedBlobs', function() { |
||||
// Create a proto consisting of two nested messages, with the inner one
|
||||
// containing a blob of bytes.
|
||||
|
||||
var fieldTag = (1 << 3) | jspb.BinaryConstants.WireType.DELIMITED; |
||||
var blob = [1, 2, 3, 4, 5]; |
||||
var writer = new jspb.BinaryWriter(); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
|
||||
writer.writeMessage(1, dummyMessage, function() { |
||||
writer.writeMessage(1, dummyMessage, function() { |
||||
writer.writeBytes(1, blob); |
||||
}); |
||||
}); |
||||
|
||||
// Peel off the outer two message layers. Each layer should have two bytes
|
||||
// of overhead, one for the field tag and one for the length of the inner
|
||||
// blob.
|
||||
|
||||
var decoder1 = new jspb.BinaryDecoder(writer.getResultBuffer()); |
||||
assertEquals(fieldTag, decoder1.readUnsignedVarint32()); |
||||
assertEquals(blob.length + 4, decoder1.readUnsignedVarint32()); |
||||
|
||||
var decoder2 = new jspb.BinaryDecoder(decoder1.readBytes(blob.length + 4)); |
||||
assertEquals(fieldTag, decoder2.readUnsignedVarint32()); |
||||
assertEquals(blob.length + 2, decoder2.readUnsignedVarint32()); |
||||
|
||||
assertEquals(fieldTag, decoder2.readUnsignedVarint32()); |
||||
assertEquals(blob.length, decoder2.readUnsignedVarint32()); |
||||
var bytes = decoder2.readBytes(blob.length); |
||||
|
||||
assertElementsEquals(bytes, blob); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests read callbacks. |
||||
*/ |
||||
it('testReadCallbacks', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
|
||||
// Add an int, a submessage, and another int.
|
||||
writer.writeInt32(1, 100); |
||||
|
||||
writer.writeMessage(2, dummyMessage, function() { |
||||
writer.writeInt32(3, 300); |
||||
writer.writeInt32(4, 400); |
||||
writer.writeInt32(5, 500); |
||||
}); |
||||
|
||||
writer.writeInt32(7, 700); |
||||
|
||||
// Create the reader and register a custom read callback.
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); |
||||
|
||||
/** |
||||
* @param {!jspb.BinaryReader} reader |
||||
* @return {*} |
||||
*/ |
||||
function readCallback(reader) { |
||||
reader.nextField(); |
||||
assertEquals(3, reader.getFieldNumber()); |
||||
assertEquals(300, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(4, reader.getFieldNumber()); |
||||
assertEquals(400, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(5, reader.getFieldNumber()); |
||||
assertEquals(500, reader.readInt32()); |
||||
|
||||
assertEquals(false, reader.nextField()); |
||||
}; |
||||
|
||||
reader.registerReadCallback('readCallback', readCallback); |
||||
|
||||
// Read the container message.
|
||||
reader.nextField(); |
||||
assertEquals(1, reader.getFieldNumber()); |
||||
assertEquals(100, reader.readInt32()); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(2, reader.getFieldNumber()); |
||||
reader.readMessage(dummyMessage, function() { |
||||
// Decode the embedded message using the registered callback.
|
||||
reader.runReadCallback('readCallback'); |
||||
}); |
||||
|
||||
reader.nextField(); |
||||
assertEquals(7, reader.getFieldNumber()); |
||||
assertEquals(700, reader.readInt32()); |
||||
|
||||
assertEquals(false, reader.nextField()); |
||||
}); |
||||
}); |
@ -0,0 +1,668 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/** |
||||
* @fileoverview Test cases for jspb's helper functions. |
||||
* |
||||
* Test suite is written using Jasmine -- see http://jasmine.github.io/
|
||||
* |
||||
* @author aappleby@google.com (Austin Appleby) |
||||
*/ |
||||
|
||||
goog.require('goog.crypt.base64'); |
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('jspb.BinaryConstants'); |
||||
goog.require('jspb.BinaryWriter'); |
||||
goog.require('jspb.utils'); |
||||
|
||||
|
||||
/** |
||||
* @param {number} x |
||||
* @return {number} |
||||
*/ |
||||
function truncate(x) { |
||||
var temp = new Float32Array(1); |
||||
temp[0] = x; |
||||
return temp[0]; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Converts an 64-bit integer in split representation to a 64-bit hash string |
||||
* (8 bits encoded per character). |
||||
* @param {number} bitsLow The low 32 bits of the split 64-bit integer. |
||||
* @param {number} bitsHigh The high 32 bits of the split 64-bit integer. |
||||
* @return {string} The encoded hash string, 8 bits per character. |
||||
*/ |
||||
function toHashString(bitsLow, bitsHigh) { |
||||
return String.fromCharCode((bitsLow >>> 0) & 0xFF, |
||||
(bitsLow >>> 8) & 0xFF, |
||||
(bitsLow >>> 16) & 0xFF, |
||||
(bitsLow >>> 24) & 0xFF, |
||||
(bitsHigh >>> 0) & 0xFF, |
||||
(bitsHigh >>> 8) & 0xFF, |
||||
(bitsHigh >>> 16) & 0xFF, |
||||
(bitsHigh >>> 24) & 0xFF); |
||||
} |
||||
|
||||
|
||||
describe('binaryUtilsTest', function() { |
||||
/** |
||||
* Tests lossless binary-to-decimal conversion. |
||||
*/ |
||||
it('testDecimalConversion', function() { |
||||
// Check some magic numbers.
|
||||
var result = |
||||
jspb.utils.joinUnsignedDecimalString(0x89e80001, 0x8ac72304); |
||||
assertEquals('10000000000000000001', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0xacd05f15, 0x1b69b4b); |
||||
assertEquals('123456789123456789', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0xeb1f0ad2, 0xab54a98c); |
||||
assertEquals('12345678901234567890', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0xe3b70cb1, 0x891087b8); |
||||
assertEquals('9876543210987654321', result); |
||||
|
||||
// Check limits.
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00000000); |
||||
assertEquals('0', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0xFFFFFFFF, 0xFFFFFFFF); |
||||
assertEquals('18446744073709551615', result); |
||||
|
||||
// Check each bit of the low dword.
|
||||
for (var i = 0; i < 32; i++) { |
||||
var low = (1 << i) >>> 0; |
||||
result = jspb.utils.joinUnsignedDecimalString(low, 0); |
||||
assertEquals('' + Math.pow(2, i), result); |
||||
} |
||||
|
||||
// Check the first 20 bits of the high dword.
|
||||
for (var i = 0; i < 20; i++) { |
||||
var high = (1 << i) >>> 0; |
||||
result = jspb.utils.joinUnsignedDecimalString(0, high); |
||||
assertEquals('' + Math.pow(2, 32 + i), result); |
||||
} |
||||
|
||||
// V8's internal double-to-string conversion is inaccurate for values above
|
||||
// 2^52, even if they're representable integers - check the rest of the bits
|
||||
// manually against the correct string representations of 2^N.
|
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00100000); |
||||
assertEquals('4503599627370496', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00200000); |
||||
assertEquals('9007199254740992', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00400000); |
||||
assertEquals('18014398509481984', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00800000); |
||||
assertEquals('36028797018963968', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x01000000); |
||||
assertEquals('72057594037927936', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x02000000); |
||||
assertEquals('144115188075855872', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x04000000); |
||||
assertEquals('288230376151711744', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x08000000); |
||||
assertEquals('576460752303423488', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x10000000); |
||||
assertEquals('1152921504606846976', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x20000000); |
||||
assertEquals('2305843009213693952', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x40000000); |
||||
assertEquals('4611686018427387904', result); |
||||
|
||||
result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x80000000); |
||||
assertEquals('9223372036854775808', result); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Going from hash strings to decimal strings should also be lossless. |
||||
*/ |
||||
it('testHashToDecimalConversion', function() { |
||||
var result; |
||||
var convert = jspb.utils.hash64ToDecimalString; |
||||
|
||||
result = convert(toHashString(0x00000000, 0x00000000), false); |
||||
assertEquals('0', result); |
||||
|
||||
result = convert(toHashString(0x00000000, 0x00000000), true); |
||||
assertEquals('0', result); |
||||
|
||||
result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF), false); |
||||
assertEquals('18446744073709551615', result); |
||||
|
||||
result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF), true); |
||||
assertEquals('-1', result); |
||||
|
||||
result = convert(toHashString(0x00000000, 0x80000000), false); |
||||
assertEquals('9223372036854775808', result); |
||||
|
||||
result = convert(toHashString(0x00000000, 0x80000000), true); |
||||
assertEquals('-9223372036854775808', result); |
||||
|
||||
result = convert(toHashString(0xacd05f15, 0x01b69b4b), false); |
||||
assertEquals('123456789123456789', result); |
||||
|
||||
result = convert(toHashString(~0xacd05f15 + 1, ~0x01b69b4b), true); |
||||
assertEquals('-123456789123456789', result); |
||||
|
||||
// And converting arrays of hashes should work the same way.
|
||||
result = jspb.utils.hash64ArrayToDecimalStrings([ |
||||
toHashString(0xFFFFFFFF, 0xFFFFFFFF), |
||||
toHashString(0x00000000, 0x80000000), |
||||
toHashString(0xacd05f15, 0x01b69b4b)], false); |
||||
assertEquals(3, result.length); |
||||
assertEquals('18446744073709551615', result[0]); |
||||
assertEquals('9223372036854775808', result[1]); |
||||
assertEquals('123456789123456789', result[2]); |
||||
}); |
||||
|
||||
/* |
||||
* Going from decimal strings to hash strings should be lossless. |
||||
*/ |
||||
it('testDecimalToHashConversion', function() { |
||||
var result; |
||||
var convert = jspb.utils.decimalStringToHash64; |
||||
|
||||
result = convert('0'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result); |
||||
|
||||
result = convert('-1'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); |
||||
|
||||
result = convert('18446744073709551615'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); |
||||
|
||||
result = convert('9223372036854775808'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result); |
||||
|
||||
result = convert('-9223372036854775808'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result); |
||||
|
||||
result = convert('123456789123456789'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0x15, 0x5F, 0xD0, 0xAC, 0x4B, 0x9B, 0xB6, 0x01]), result); |
||||
|
||||
result = convert('-123456789123456789'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0xEB, 0xA0, 0x2F, 0x53, 0xB4, 0x64, 0x49, 0xFE]), result); |
||||
}); |
||||
|
||||
/** |
||||
* Going from hash strings to hex strings should be lossless. |
||||
*/ |
||||
it('testHashToHexConversion', function() { |
||||
var result; |
||||
var convert = jspb.utils.hash64ToHexString; |
||||
|
||||
result = convert(toHashString(0x00000000, 0x00000000)); |
||||
assertEquals('0x0000000000000000', result); |
||||
|
||||
result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF)); |
||||
assertEquals('0xffffffffffffffff', result); |
||||
|
||||
result = convert(toHashString(0x12345678, 0x9ABCDEF0)); |
||||
assertEquals('0x9abcdef012345678', result); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Going from hex strings to hash strings should be lossless. |
||||
*/ |
||||
it('testHexToHashConversion', function() { |
||||
var result; |
||||
var convert = jspb.utils.hexStringToHash64; |
||||
|
||||
result = convert('0x0000000000000000'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result); |
||||
|
||||
result = convert('0xffffffffffffffff'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); |
||||
|
||||
// Hex string is big-endian, hash string is little-endian.
|
||||
result = convert('0x123456789ABCDEF0'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]), result); |
||||
|
||||
// Capitalization should not matter.
|
||||
result = convert('0x0000abcdefABCDEF'); |
||||
assertEquals(String.fromCharCode.apply(null, |
||||
[0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB, 0x00, 0x00]), result); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Going from numbers to hash strings should be lossless for up to 53 bits of |
||||
* precision. |
||||
*/ |
||||
it('testNumberToHashConversion', function() { |
||||
var result; |
||||
var convert = jspb.utils.numberToHash64; |
||||
|
||||
result = convert(0x0000000000000); |
||||
assertEquals('0x0000000000000000', jspb.utils.hash64ToHexString(result)); |
||||
|
||||
result = convert(0xFFFFFFFFFFFFF); |
||||
assertEquals('0x000fffffffffffff', jspb.utils.hash64ToHexString(result)); |
||||
|
||||
result = convert(0x123456789ABCD); |
||||
assertEquals('0x000123456789abcd', jspb.utils.hash64ToHexString(result)); |
||||
|
||||
result = convert(0xDCBA987654321); |
||||
assertEquals('0x000dcba987654321', jspb.utils.hash64ToHexString(result)); |
||||
|
||||
// 53 bits of precision should not be truncated.
|
||||
result = convert(0x10000000000001); |
||||
assertEquals('0x0010000000000001', jspb.utils.hash64ToHexString(result)); |
||||
|
||||
// 54 bits of precision should be truncated.
|
||||
result = convert(0x20000000000001); |
||||
assertNotEquals( |
||||
'0x0020000000000001', jspb.utils.hash64ToHexString(result)); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Sanity check the behavior of Javascript's strings when doing funny things |
||||
* with unicode characters. |
||||
*/ |
||||
it('sanityCheckUnicodeStrings', function() { |
||||
var strings = new Array(65536); |
||||
|
||||
// All possible unsigned 16-bit values should be storable in a string, they
|
||||
// shouldn't do weird things with the length of the string, and they should
|
||||
// come back out of the string unchanged.
|
||||
for (var i = 0; i < 65536; i++) { |
||||
strings[i] = 'a' + String.fromCharCode(i) + 'a'; |
||||
if (3 != strings[i].length) throw 'fail!'; |
||||
if (i != strings[i].charCodeAt(1)) throw 'fail!'; |
||||
} |
||||
|
||||
// Each unicode character should compare equal to itself and not equal to a
|
||||
// different unicode character.
|
||||
for (var i = 0; i < 65536; i++) { |
||||
if (strings[i] != strings[i]) throw 'fail!'; |
||||
if (strings[i] == strings[(i + 1) % 65536]) throw 'fail!'; |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests conversion from 32-bit floating point numbers to split64 numbers. |
||||
*/ |
||||
it('testFloat32ToSplit64', function() { |
||||
var f32_eps = jspb.BinaryConstants.FLOAT32_EPS; |
||||
var f32_min = jspb.BinaryConstants.FLOAT32_MIN; |
||||
var f32_max = jspb.BinaryConstants.FLOAT32_MAX; |
||||
|
||||
// NaN.
|
||||
jspb.utils.splitFloat32(NaN); |
||||
if (!isNaN(jspb.utils.joinFloat32(jspb.utils.split64Low, |
||||
jspb.utils.split64High))) { |
||||
throw 'fail!'; |
||||
} |
||||
|
||||
/** |
||||
* @param {number} x |
||||
* @param {number=} opt_bits |
||||
*/ |
||||
function test(x, opt_bits) { |
||||
jspb.utils.splitFloat32(x); |
||||
if (goog.isDef(opt_bits)) { |
||||
if (opt_bits != jspb.utils.split64Low) throw 'fail!'; |
||||
} |
||||
if (truncate(x) != jspb.utils.joinFloat32(jspb.utils.split64Low, |
||||
jspb.utils.split64High)) { |
||||
throw 'fail!'; |
||||
} |
||||
} |
||||
|
||||
// Positive and negative infinity.
|
||||
test(Infinity, 0x7f800000); |
||||
test(-Infinity, 0xff800000); |
||||
|
||||
// Positive and negative zero.
|
||||
test(0, 0x00000000); |
||||
test(-0, 0x80000000); |
||||
|
||||
// Positive and negative epsilon.
|
||||
test(f32_eps, 0x00000001); |
||||
test(-f32_eps, 0x80000001); |
||||
|
||||
// Positive and negative min.
|
||||
test(f32_min, 0x00800000); |
||||
test(-f32_min, 0x80800000); |
||||
|
||||
// Positive and negative max.
|
||||
test(f32_max, 0x7F7FFFFF); |
||||
test(-f32_max, 0xFF7FFFFF); |
||||
|
||||
// Various positive values.
|
||||
var cursor = f32_eps * 10; |
||||
while (cursor != Infinity) { |
||||
test(cursor); |
||||
cursor *= 1.1; |
||||
} |
||||
|
||||
// Various negative values.
|
||||
cursor = -f32_eps * 10; |
||||
while (cursor != -Infinity) { |
||||
test(cursor); |
||||
cursor *= 1.1; |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests conversion from 64-bit floating point numbers to split64 numbers. |
||||
*/ |
||||
it('testFloat64ToSplit64', function() { |
||||
var f64_eps = jspb.BinaryConstants.FLOAT64_EPS; |
||||
var f64_min = jspb.BinaryConstants.FLOAT64_MIN; |
||||
var f64_max = jspb.BinaryConstants.FLOAT64_MAX; |
||||
|
||||
// NaN.
|
||||
jspb.utils.splitFloat64(NaN); |
||||
if (!isNaN(jspb.utils.joinFloat64(jspb.utils.split64Low, |
||||
jspb.utils.split64High))) { |
||||
throw 'fail!'; |
||||
} |
||||
|
||||
/** |
||||
* @param {number} x |
||||
* @param {number=} opt_highBits |
||||
* @param {number=} opt_lowBits |
||||
*/ |
||||
function test(x, opt_highBits, opt_lowBits) { |
||||
jspb.utils.splitFloat64(x); |
||||
if (goog.isDef(opt_highBits)) { |
||||
if (opt_highBits != jspb.utils.split64High) throw 'fail!'; |
||||
} |
||||
if (goog.isDef(opt_lowBits)) { |
||||
if (opt_lowBits != jspb.utils.split64Low) throw 'fail!'; |
||||
} |
||||
if (x != jspb.utils.joinFloat64(jspb.utils.split64Low, |
||||
jspb.utils.split64High)) { |
||||
throw 'fail!'; |
||||
} |
||||
} |
||||
|
||||
// Positive and negative infinity.
|
||||
test(Infinity, 0x7ff00000, 0x00000000); |
||||
test(-Infinity, 0xfff00000, 0x00000000); |
||||
|
||||
// Positive and negative zero.
|
||||
test(0, 0x00000000, 0x00000000); |
||||
test(-0, 0x80000000, 0x00000000); |
||||
|
||||
// Positive and negative epsilon.
|
||||
test(f64_eps, 0x00000000, 0x00000001); |
||||
test(-f64_eps, 0x80000000, 0x00000001); |
||||
|
||||
// Positive and negative min.
|
||||
test(f64_min, 0x00100000, 0x00000000); |
||||
test(-f64_min, 0x80100000, 0x00000000); |
||||
|
||||
// Positive and negative max.
|
||||
test(f64_max, 0x7FEFFFFF, 0xFFFFFFFF); |
||||
test(-f64_max, 0xFFEFFFFF, 0xFFFFFFFF); |
||||
|
||||
// Various positive values.
|
||||
var cursor = f64_eps * 10; |
||||
while (cursor != Infinity) { |
||||
test(cursor); |
||||
cursor *= 1.1; |
||||
} |
||||
|
||||
// Various negative values.
|
||||
cursor = -f64_eps * 10; |
||||
while (cursor != -Infinity) { |
||||
test(cursor); |
||||
cursor *= 1.1; |
||||
} |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests counting packed varints. |
||||
*/ |
||||
it('testCountVarints', function() { |
||||
var values = []; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
values.push(Math.floor(i)); |
||||
} |
||||
|
||||
var writer = new jspb.BinaryWriter(); |
||||
writer.writePackedUint64(1, values); |
||||
|
||||
var buffer = new Uint8Array(writer.getResultBuffer()); |
||||
|
||||
// We should have two more varints than we started with - one for the field
|
||||
// tag, one for the packed length.
|
||||
assertEquals(values.length + 2, |
||||
jspb.utils.countVarints(buffer, 0, buffer.length)); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests counting matching varint fields. |
||||
*/ |
||||
it('testCountVarintFields', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var count = 0; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
writer.writeUint64(1, Math.floor(i)); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
var buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countVarintFields(buffer, 0, buffer.length, 1)); |
||||
|
||||
writer = new jspb.BinaryWriter(); |
||||
|
||||
count = 0; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
writer.writeUint64(123456789, Math.floor(i)); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countVarintFields(buffer, 0, buffer.length, 123456789)); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests counting matching fixed32 fields. |
||||
*/ |
||||
it('testCountFixed32Fields', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var count = 0; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
writer.writeFixed32(1, Math.floor(i)); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
var buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countFixed32Fields(buffer, 0, buffer.length, 1)); |
||||
|
||||
writer = new jspb.BinaryWriter(); |
||||
|
||||
count = 0; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
writer.writeFixed32(123456789, Math.floor(i)); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countFixed32Fields(buffer, 0, buffer.length, 123456789)); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests counting matching fixed64 fields. |
||||
*/ |
||||
it('testCountFixed64Fields', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var count = 0; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
writer.writeDouble(1, i); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
var buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countFixed64Fields(buffer, 0, buffer.length, 1)); |
||||
|
||||
writer = new jspb.BinaryWriter(); |
||||
|
||||
count = 0; |
||||
for (var i = 1; i < 1000000000; i *= 1.1) { |
||||
writer.writeDouble(123456789, i); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countFixed64Fields(buffer, 0, buffer.length, 123456789)); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests counting matching delimited fields. |
||||
*/ |
||||
it('testCountDelimitedFields', function() { |
||||
var writer = new jspb.BinaryWriter(); |
||||
|
||||
var count = 0; |
||||
for (var i = 1; i < 1000; i *= 1.1) { |
||||
writer.writeBytes(1, [Math.floor(i)]); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
var buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countDelimitedFields(buffer, 0, buffer.length, 1)); |
||||
|
||||
writer = new jspb.BinaryWriter(); |
||||
|
||||
count = 0; |
||||
for (var i = 1; i < 1000; i *= 1.1) { |
||||
writer.writeBytes(123456789, [Math.floor(i)]); |
||||
count++; |
||||
} |
||||
writer.writeString(2, 'terminator'); |
||||
|
||||
buffer = new Uint8Array(writer.getResultBuffer()); |
||||
assertEquals(count, |
||||
jspb.utils.countDelimitedFields(buffer, 0, buffer.length, 123456789)); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests byte format for debug strings. |
||||
*/ |
||||
it('testDebugBytesToTextFormat', function() { |
||||
assertEquals('""', jspb.utils.debugBytesToTextFormat(null)); |
||||
assertEquals('"\\x00\\x10\\xff"', |
||||
jspb.utils.debugBytesToTextFormat([0, 16, 255])); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests converting byte blob sources into byte blobs. |
||||
*/ |
||||
it('testByteSourceToUint8Array', function() { |
||||
var convert = jspb.utils.byteSourceToUint8Array; |
||||
|
||||
var sourceData = []; |
||||
for (var i = 0; i < 256; i++) { |
||||
sourceData.push(i); |
||||
} |
||||
|
||||
var sourceBytes = new Uint8Array(sourceData); |
||||
var sourceBuffer = sourceBytes.buffer; |
||||
var sourceBase64 = goog.crypt.base64.encodeByteArray(sourceData); |
||||
var sourceString = String.fromCharCode.apply(null, sourceData); |
||||
|
||||
function check(result) { |
||||
assertEquals(Uint8Array, result.constructor); |
||||
assertEquals(sourceData.length, result.length); |
||||
for (var i = 0; i < result.length; i++) { |
||||
assertEquals(sourceData[i], result[i]); |
||||
} |
||||
} |
||||
|
||||
// Converting Uint8Arrays into Uint8Arrays should be a no-op.
|
||||
assertEquals(sourceBytes, convert(sourceBytes)); |
||||
|
||||
// Converting Array.<numbers> into Uint8Arrays should work.
|
||||
check(convert(sourceData)); |
||||
|
||||
// Converting ArrayBuffers into Uint8Arrays should work.
|
||||
check(convert(sourceBuffer)); |
||||
|
||||
// Converting base64-encoded strings into Uint8Arrays should work.
|
||||
check(convert(sourceBase64)); |
||||
}); |
||||
}); |
@ -0,0 +1,122 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
/** |
||||
* @fileoverview Test cases for jspb's binary protocol buffer writer. In |
||||
* practice BinaryWriter is used to drive the Decoder and Reader test cases, |
||||
* so only writer-specific tests are here. |
||||
* |
||||
* Test suite is written using Jasmine -- see http://jasmine.github.io/
|
||||
* |
||||
* @author aappleby@google.com (Austin Appleby) |
||||
*/ |
||||
|
||||
goog.require('goog.crypt'); |
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('jspb.BinaryWriter'); |
||||
|
||||
|
||||
/** |
||||
* @param {function()} func This function should throw an error when run. |
||||
*/ |
||||
function assertFails(func) { |
||||
var e = assertThrows(func); |
||||
//assertNotNull(e.toString().match(/Error/));
|
||||
} |
||||
|
||||
|
||||
describe('binaryWriterTest', function() { |
||||
/** |
||||
* Verifies that misuse of the writer class triggers assertions. |
||||
*/ |
||||
it('testWriteErrors', function() { |
||||
// Submessages with invalid field indices should assert.
|
||||
var writer = new jspb.BinaryWriter(); |
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); |
||||
|
||||
assertFails(function() { |
||||
writer.writeMessage(-1, dummyMessage, goog.nullFunction); |
||||
}); |
||||
|
||||
// Writing invalid field indices should assert.
|
||||
writer = new jspb.BinaryWriter(); |
||||
assertFails(function() {writer.writeUint64(-1, 1);}); |
||||
|
||||
// Writing out-of-range field values should assert.
|
||||
writer = new jspb.BinaryWriter(); |
||||
|
||||
assertFails(function() {writer.writeInt32(1, -Infinity);}); |
||||
assertFails(function() {writer.writeInt32(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeInt64(1, -Infinity);}); |
||||
assertFails(function() {writer.writeInt64(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeUint32(1, -1);}); |
||||
assertFails(function() {writer.writeUint32(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeUint64(1, -1);}); |
||||
assertFails(function() {writer.writeUint64(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeSint32(1, -Infinity);}); |
||||
assertFails(function() {writer.writeSint32(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeSint64(1, -Infinity);}); |
||||
assertFails(function() {writer.writeSint64(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeFixed32(1, -1);}); |
||||
assertFails(function() {writer.writeFixed32(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeFixed64(1, -1);}); |
||||
assertFails(function() {writer.writeFixed64(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeSfixed32(1, -Infinity);}); |
||||
assertFails(function() {writer.writeSfixed32(1, Infinity);}); |
||||
|
||||
assertFails(function() {writer.writeSfixed64(1, -Infinity);}); |
||||
assertFails(function() {writer.writeSfixed64(1, Infinity);}); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Basic test of retrieving the result as a Uint8Array buffer |
||||
*/ |
||||
it('testGetResultBuffer', function() { |
||||
var expected = '0864120b48656c6c6f20776f726c641a0301020320c801'; |
||||
|
||||
var writer = new jspb.BinaryWriter(); |
||||
writer.writeUint32(1, 100); |
||||
writer.writeString(2, 'Hello world'); |
||||
writer.writeBytes(3, new Uint8Array([1, 2, 3])); |
||||
writer.writeUint32(4, 200); |
||||
|
||||
var buffer = writer.getResultBuffer(); |
||||
assertEquals(expected, goog.crypt.byteArrayToHex(buffer)); |
||||
}); |
||||
}); |
@ -0,0 +1,40 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2016 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.test.importing; |
||||
|
||||
message ImportedMessage { |
||||
string string_value = 1; |
||||
} |
@ -0,0 +1,42 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2016 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.test.framing; |
||||
|
||||
import "test6/test6.proto"; |
||||
|
||||
message FramingMessage { |
||||
jspb.test.importing.ImportedMessage imported_message = 1; |
||||
} |
@ -0,0 +1,51 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
// Author: mwr@google.com (Mark Rawling) |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.test; |
||||
|
||||
// legacy data, must be nested |
||||
message data { |
||||
message NestedData { |
||||
required string str = 1; |
||||
} |
||||
} |
||||
|
||||
// new data, does not require nesting |
||||
message UnnestedData { |
||||
required string str = 1; |
||||
} |
||||
|
@ -0,0 +1,105 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
goog.setTestOnly(); |
||||
|
||||
goog.require('goog.testing.asserts'); |
||||
|
||||
// CommonJS-LoadFromFile: google-protobuf
|
||||
goog.require('jspb.debug'); |
||||
|
||||
// CommonJS-LoadFromFile: test_pb
|
||||
goog.require('proto.jspb.test.HasExtensions'); |
||||
goog.require('proto.jspb.test.IsExtension'); |
||||
goog.require('proto.jspb.test.Simple1'); |
||||
|
||||
|
||||
|
||||
describe('debugTest', function() { |
||||
it('testSimple1', function() { |
||||
if (COMPILED) { |
||||
return; |
||||
} |
||||
var message = new proto.jspb.test.Simple1(); |
||||
message.setAString('foo'); |
||||
assertObjectEquals({ |
||||
$name: 'proto.jspb.test.Simple1', |
||||
'aString': 'foo', |
||||
'aRepeatedStringList': [] |
||||
}, jspb.debug.dump(message)); |
||||
|
||||
message.setABoolean(true); |
||||
message.setARepeatedStringList(['1', '2']); |
||||
|
||||
assertObjectEquals({ |
||||
$name: 'proto.jspb.test.Simple1', |
||||
'aString': 'foo', |
||||
'aRepeatedStringList': ['1', '2'], |
||||
'aBoolean': true |
||||
}, jspb.debug.dump(message)); |
||||
|
||||
message.clearAString(); |
||||
|
||||
assertObjectEquals({ |
||||
$name: 'proto.jspb.test.Simple1', |
||||
'aRepeatedStringList': ['1', '2'], |
||||
'aBoolean': true |
||||
}, jspb.debug.dump(message)); |
||||
}); |
||||
|
||||
|
||||
it('testExtensions', function() { |
||||
if (COMPILED) { |
||||
return; |
||||
} |
||||
var extension = new proto.jspb.test.IsExtension(); |
||||
extension.setExt1('ext1field'); |
||||
var extendable = new proto.jspb.test.HasExtensions(); |
||||
extendable.setStr1('v1'); |
||||
extendable.setStr2('v2'); |
||||
extendable.setStr3('v3'); |
||||
extendable.setExtension(proto.jspb.test.IsExtension.extField, extension); |
||||
|
||||
assertObjectEquals({ |
||||
'$name': 'proto.jspb.test.HasExtensions', |
||||
'str1': 'v1', |
||||
'str2': 'v2', |
||||
'str3': 'v3', |
||||
'$extensions': { |
||||
'extField': { |
||||
'$name': 'proto.jspb.test.IsExtension', |
||||
'ext1': 'ext1field' |
||||
}, |
||||
'repeatedSimpleList': [] |
||||
} |
||||
}, jspb.debug.dump(extendable)); |
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,301 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
goog.require('goog.testing.asserts'); |
||||
goog.require('goog.userAgent'); |
||||
|
||||
// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.MapValueEnum'); |
||||
goog.require('proto.jspb.test.MapValueMessage'); |
||||
goog.require('proto.jspb.test.TestMapFields'); |
||||
|
||||
// CommonJS-LoadFromFile: test_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.MapValueMessageNoBinary'); |
||||
goog.require('proto.jspb.test.TestMapFieldsNoBinary'); |
||||
|
||||
/** |
||||
* Helper: check that the given map has exactly this set of (sorted) entries. |
||||
* @param {!jspb.Map} map |
||||
* @param {!Array<!Array<?>>} entries |
||||
*/ |
||||
function checkMapEquals(map, entries) { |
||||
var arr = map.toArray(); |
||||
assertEquals(arr.length, entries.length); |
||||
for (var i = 0; i < arr.length; i++) { |
||||
assertElementsEquals(arr[i], entries[i]); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Converts an ES6 iterator to an array. |
||||
* @template T |
||||
* @param {!Iterator<T>} iter an iterator |
||||
* @return {!Array<T>} |
||||
*/ |
||||
function toArray(iter) { |
||||
var arr = []; |
||||
while (true) { |
||||
var val = iter.next(); |
||||
if (val.done) { |
||||
break; |
||||
} |
||||
arr.push(val.value); |
||||
} |
||||
return arr; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Helper: generate test methods for this TestMapFields class. |
||||
* @param {?} msgInfo |
||||
* @param {?} submessageCtor |
||||
* @param {!string} suffix |
||||
*/ |
||||
function makeTests(msgInfo, submessageCtor, suffix) { |
||||
/** |
||||
* Helper: fill all maps on a TestMapFields. |
||||
* @param {?} msg |
||||
*/ |
||||
var fillMapFields = function(msg) { |
||||
msg.getMapStringStringMap().set('asdf', 'jkl;').set('key 2', 'hello world'); |
||||
msg.getMapStringInt32Map().set('a', 1).set('b', -2); |
||||
msg.getMapStringInt64Map().set('c', 0x100000000).set('d', 0x200000000); |
||||
msg.getMapStringBoolMap().set('e', true).set('f', false); |
||||
msg.getMapStringDoubleMap().set('g', 3.14159).set('h', 2.71828); |
||||
msg.getMapStringEnumMap() |
||||
.set('i', proto.jspb.test.MapValueEnum.MAP_VALUE_BAR) |
||||
.set('j', proto.jspb.test.MapValueEnum.MAP_VALUE_BAZ); |
||||
msg.getMapStringMsgMap() |
||||
.set('k', new submessageCtor()) |
||||
.set('l', new submessageCtor()); |
||||
msg.getMapStringMsgMap().get('k').setFoo(42); |
||||
msg.getMapStringMsgMap().get('l').setFoo(84); |
||||
msg.getMapInt32StringMap().set(-1, 'a').set(42, 'b'); |
||||
msg.getMapInt64StringMap().set(0x123456789abc, 'c').set(0xcba987654321, 'd'); |
||||
msg.getMapBoolStringMap().set(false, 'e').set(true, 'f'); |
||||
}; |
||||
|
||||
/** |
||||
* Helper: check all maps on a TestMapFields. |
||||
* @param {?} msg |
||||
*/ |
||||
var checkMapFields = function(msg) { |
||||
checkMapEquals(msg.getMapStringStringMap(), [ |
||||
['asdf', 'jkl;'], |
||||
['key 2', 'hello world'] |
||||
]); |
||||
checkMapEquals(msg.getMapStringInt32Map(), [ |
||||
['a', 1], |
||||
['b', -2] |
||||
]); |
||||
checkMapEquals(msg.getMapStringInt64Map(), [ |
||||
['c', 0x100000000], |
||||
['d', 0x200000000] |
||||
]); |
||||
checkMapEquals(msg.getMapStringBoolMap(), [ |
||||
['e', true], |
||||
['f', false] |
||||
]); |
||||
checkMapEquals(msg.getMapStringDoubleMap(), [ |
||||
['g', 3.14159], |
||||
['h', 2.71828] |
||||
]); |
||||
checkMapEquals(msg.getMapStringEnumMap(), [ |
||||
['i', proto.jspb.test.MapValueEnum.MAP_VALUE_BAR], |
||||
['j', proto.jspb.test.MapValueEnum.MAP_VALUE_BAZ] |
||||
]); |
||||
checkMapEquals(msg.getMapInt32StringMap(), [ |
||||
[-1, 'a'], |
||||
[42, 'b'] |
||||
]); |
||||
checkMapEquals(msg.getMapInt64StringMap(), [ |
||||
[0x123456789abc, 'c'], |
||||
[0xcba987654321, 'd'] |
||||
]); |
||||
checkMapEquals(msg.getMapBoolStringMap(), [ |
||||
[false, 'e'], |
||||
[true, 'f'] |
||||
]); |
||||
|
||||
assertEquals(msg.getMapStringMsgMap().getLength(), 2); |
||||
assertEquals(msg.getMapStringMsgMap().get('k').getFoo(), 42); |
||||
assertEquals(msg.getMapStringMsgMap().get('l').getFoo(), 84); |
||||
|
||||
var entries = toArray(msg.getMapStringMsgMap().entries()); |
||||
assertEquals(entries.length, 2); |
||||
entries.forEach(function(entry) { |
||||
var key = entry[0]; |
||||
var val = entry[1]; |
||||
assert(val === msg.getMapStringMsgMap().get(key)); |
||||
}); |
||||
|
||||
msg.getMapStringMsgMap().forEach(function(val, key) { |
||||
assert(val === msg.getMapStringMsgMap().get(key)); |
||||
}); |
||||
}; |
||||
|
||||
it('testMapStringStringField' + suffix, function() { |
||||
var msg = new msgInfo.constructor(); |
||||
assertEquals(msg.getMapStringStringMap().getLength(), 0); |
||||
assertEquals(msg.getMapStringInt32Map().getLength(), 0); |
||||
assertEquals(msg.getMapStringInt64Map().getLength(), 0); |
||||
assertEquals(msg.getMapStringBoolMap().getLength(), 0); |
||||
assertEquals(msg.getMapStringDoubleMap().getLength(), 0); |
||||
assertEquals(msg.getMapStringEnumMap().getLength(), 0); |
||||
assertEquals(msg.getMapStringMsgMap().getLength(), 0); |
||||
|
||||
// Re-create to clear out any internally-cached wrappers, etc.
|
||||
msg = new msgInfo.constructor(); |
||||
var m = msg.getMapStringStringMap(); |
||||
assertEquals(m.has('asdf'), false); |
||||
assertEquals(m.get('asdf'), undefined); |
||||
m.set('asdf', 'hello world'); |
||||
assertEquals(m.has('asdf'), true); |
||||
assertEquals(m.get('asdf'), 'hello world'); |
||||
m.set('jkl;', 'key 2'); |
||||
assertEquals(m.has('jkl;'), true); |
||||
assertEquals(m.get('jkl;'), 'key 2'); |
||||
assertEquals(m.getLength(), 2); |
||||
var it = m.entries(); |
||||
assertElementsEquals(it.next().value, ['asdf', 'hello world']); |
||||
assertElementsEquals(it.next().value, ['jkl;', 'key 2']); |
||||
assertEquals(it.next().done, true); |
||||
checkMapEquals(m, [ |
||||
['asdf', 'hello world'], |
||||
['jkl;', 'key 2'] |
||||
]); |
||||
m.del('jkl;'); |
||||
assertEquals(m.has('jkl;'), false); |
||||
assertEquals(m.get('jkl;'), undefined); |
||||
assertEquals(m.getLength(), 1); |
||||
it = m.keys(); |
||||
assertEquals(it.next().value, 'asdf'); |
||||
assertEquals(it.next().done, true); |
||||
it = m.values(); |
||||
assertEquals(it.next().value, 'hello world'); |
||||
assertEquals(it.next().done, true); |
||||
|
||||
var count = 0; |
||||
m.forEach(function(value, key, map) { |
||||
assertEquals(map, m); |
||||
assertEquals(key, 'asdf'); |
||||
assertEquals(value, 'hello world'); |
||||
count++; |
||||
}); |
||||
assertEquals(count, 1); |
||||
|
||||
m.clear(); |
||||
assertEquals(m.getLength(), 0); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Tests operations on maps with all key and value types. |
||||
*/ |
||||
it('testAllMapTypes' + suffix, function() { |
||||
var msg = new msgInfo.constructor(); |
||||
fillMapFields(msg); |
||||
checkMapFields(msg); |
||||
}); |
||||
|
||||
|
||||
if (msgInfo.deserializeBinary) { |
||||
/** |
||||
* Tests serialization and deserialization in binary format. |
||||
*/ |
||||
it('testBinaryFormat' + suffix, function() { |
||||
if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(10)) { |
||||
// IE8/9 currently doesn't support binary format because they lack
|
||||
// TypedArray.
|
||||
return; |
||||
} |
||||
|
||||
// Check that the format is correct.
|
||||
var msg = new msgInfo.constructor(); |
||||
msg.getMapStringStringMap().set('A', 'a'); |
||||
var serialized = msg.serializeBinary(); |
||||
var expectedSerialized = [ |
||||
0x0a, 0x6, // field 1 (map_string_string), delimited, length 6
|
||||
0x0a, 0x1, // field 1 in submessage (key), delimited, length 1
|
||||
0x41, // ASCII 'A'
|
||||
0x12, 0x1, // field 2 in submessage (value), delimited, length 1
|
||||
0x61 // ASCII 'a'
|
||||
]; |
||||
assertEquals(serialized.length, expectedSerialized.length); |
||||
for (var i = 0; i < serialized.length; i++) { |
||||
assertEquals(serialized[i], expectedSerialized[i]); |
||||
} |
||||
|
||||
// Check that all map fields successfully round-trip.
|
||||
msg = new msgInfo.constructor(); |
||||
fillMapFields(msg); |
||||
serialized = msg.serializeBinary(); |
||||
var decoded = msgInfo.deserializeBinary(serialized); |
||||
checkMapFields(decoded); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Exercises the lazy map<->underlying array sync. |
||||
*/ |
||||
it('testLazyMapSync' + suffix, function() { |
||||
// Start with a JSPB array containing a few map entries.
|
||||
var entries = [ |
||||
['a', 'entry 1'], |
||||
['c', 'entry 2'], |
||||
['b', 'entry 3'] |
||||
]; |
||||
var msg = new msgInfo.constructor([entries]); |
||||
assertEquals(entries.length, 3); |
||||
assertEquals(entries[0][0], 'a'); |
||||
assertEquals(entries[1][0], 'c'); |
||||
assertEquals(entries[2][0], 'b'); |
||||
msg.getMapStringStringMap().del('a'); |
||||
assertEquals(entries.length, 3); // not yet sync'd
|
||||
msg.toArray(); // force a sync
|
||||
assertEquals(entries.length, 2); |
||||
assertEquals(entries[0][0], 'b'); // now in sorted order
|
||||
assertEquals(entries[1][0], 'c'); |
||||
|
||||
var a = msg.toArray(); |
||||
assertEquals(a[0], entries); // retains original reference
|
||||
}); |
||||
} |
||||
|
||||
describe('mapsTest', function() { |
||||
makeTests({ |
||||
constructor: proto.jspb.test.TestMapFields, |
||||
deserializeBinary: proto.jspb.test.TestMapFields.deserializeBinary |
||||
}, proto.jspb.test.MapValueMessage, "_Binary"); |
||||
makeTests({ |
||||
constructor: proto.jspb.test.TestMapFieldsNoBinary, |
||||
deserializeBinary: null |
||||
}, proto.jspb.test.MapValueMessageNoBinary, "_NoBinary"); |
||||
}); |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,329 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
goog.require('goog.crypt.base64'); |
||||
goog.require('goog.testing.asserts'); |
||||
|
||||
// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.ForeignMessage'); |
||||
|
||||
// CommonJS-LoadFromFile: proto3_test_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.Proto3Enum'); |
||||
goog.require('proto.jspb.test.TestProto3'); |
||||
|
||||
|
||||
var BYTES = new Uint8Array([1, 2, 8, 9]); |
||||
var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES); |
||||
|
||||
|
||||
/** |
||||
* Helper: compare a bytes field to an expected value |
||||
* @param {Uint8Array|string} arr |
||||
* @param {Uint8Array} expected |
||||
* @return {boolean} |
||||
*/ |
||||
function bytesCompare(arr, expected) { |
||||
if (goog.isString(arr)) { |
||||
arr = goog.crypt.base64.decodeStringToUint8Array(arr); |
||||
} |
||||
if (arr.length != expected.length) { |
||||
return false; |
||||
} |
||||
for (var i = 0; i < arr.length; i++) { |
||||
if (arr[i] != expected[i]) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
describe('proto3Test', function() { |
||||
/** |
||||
* Test defaults for proto3 message fields. |
||||
*/ |
||||
it('testProto3FieldDefaults', function() { |
||||
var msg = new proto.jspb.test.TestProto3(); |
||||
|
||||
assertEquals(msg.getOptionalInt32(), 0); |
||||
assertEquals(msg.getOptionalInt64(), 0); |
||||
assertEquals(msg.getOptionalUint32(), 0); |
||||
assertEquals(msg.getOptionalUint64(), 0); |
||||
assertEquals(msg.getOptionalSint32(), 0); |
||||
assertEquals(msg.getOptionalSint64(), 0); |
||||
assertEquals(msg.getOptionalFixed32(), 0); |
||||
assertEquals(msg.getOptionalFixed64(), 0); |
||||
assertEquals(msg.getOptionalSfixed32(), 0); |
||||
assertEquals(msg.getOptionalSfixed64(), 0); |
||||
assertEquals(msg.getOptionalFloat(), 0); |
||||
assertEquals(msg.getOptionalDouble(), 0); |
||||
assertEquals(msg.getOptionalString(), ''); |
||||
|
||||
// TODO(b/26173701): when we change bytes fields default getter to return
|
||||
// Uint8Array, we'll want to switch this assertion to match the u8 case.
|
||||
assertEquals(typeof msg.getOptionalBytes(), 'string'); |
||||
assertEquals(msg.getOptionalBytes_asU8() instanceof Uint8Array, true); |
||||
assertEquals(typeof msg.getOptionalBytes_asB64(), 'string'); |
||||
assertEquals(msg.getOptionalBytes().length, 0); |
||||
assertEquals(msg.getOptionalBytes_asU8().length, 0); |
||||
assertEquals(msg.getOptionalBytes_asB64(), ''); |
||||
|
||||
assertEquals(msg.getOptionalForeignEnum(), |
||||
proto.jspb.test.Proto3Enum.PROTO3_FOO); |
||||
assertEquals(msg.getOptionalForeignMessage(), undefined); |
||||
assertEquals(msg.getOptionalForeignMessage(), undefined); |
||||
|
||||
assertEquals(msg.getRepeatedInt32List().length, 0); |
||||
assertEquals(msg.getRepeatedInt64List().length, 0); |
||||
assertEquals(msg.getRepeatedUint32List().length, 0); |
||||
assertEquals(msg.getRepeatedUint64List().length, 0); |
||||
assertEquals(msg.getRepeatedSint32List().length, 0); |
||||
assertEquals(msg.getRepeatedSint64List().length, 0); |
||||
assertEquals(msg.getRepeatedFixed32List().length, 0); |
||||
assertEquals(msg.getRepeatedFixed64List().length, 0); |
||||
assertEquals(msg.getRepeatedSfixed32List().length, 0); |
||||
assertEquals(msg.getRepeatedSfixed64List().length, 0); |
||||
assertEquals(msg.getRepeatedFloatList().length, 0); |
||||
assertEquals(msg.getRepeatedDoubleList().length, 0); |
||||
assertEquals(msg.getRepeatedStringList().length, 0); |
||||
assertEquals(msg.getRepeatedBytesList().length, 0); |
||||
assertEquals(msg.getRepeatedForeignEnumList().length, 0); |
||||
assertEquals(msg.getRepeatedForeignMessageList().length, 0); |
||||
|
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Test that all fields can be set and read via a serialization roundtrip. |
||||
*/ |
||||
it('testProto3FieldSetGet', function() { |
||||
var msg = new proto.jspb.test.TestProto3(); |
||||
|
||||
msg.setOptionalInt32(-42); |
||||
msg.setOptionalInt64(-0x7fffffff00000000); |
||||
msg.setOptionalUint32(0x80000000); |
||||
msg.setOptionalUint64(0xf000000000000000); |
||||
msg.setOptionalSint32(-100); |
||||
msg.setOptionalSint64(-0x8000000000000000); |
||||
msg.setOptionalFixed32(1234); |
||||
msg.setOptionalFixed64(0x1234567800000000); |
||||
msg.setOptionalSfixed32(-1234); |
||||
msg.setOptionalSfixed64(-0x1234567800000000); |
||||
msg.setOptionalFloat(1.5); |
||||
msg.setOptionalDouble(-1.5); |
||||
msg.setOptionalBool(true); |
||||
msg.setOptionalString('hello world'); |
||||
msg.setOptionalBytes(BYTES); |
||||
var submsg = new proto.jspb.test.ForeignMessage(); |
||||
submsg.setC(16); |
||||
msg.setOptionalForeignMessage(submsg); |
||||
msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR); |
||||
|
||||
msg.setRepeatedInt32List([-42]); |
||||
msg.setRepeatedInt64List([-0x7fffffff00000000]); |
||||
msg.setRepeatedUint32List([0x80000000]); |
||||
msg.setRepeatedUint64List([0xf000000000000000]); |
||||
msg.setRepeatedSint32List([-100]); |
||||
msg.setRepeatedSint64List([-0x8000000000000000]); |
||||
msg.setRepeatedFixed32List([1234]); |
||||
msg.setRepeatedFixed64List([0x1234567800000000]); |
||||
msg.setRepeatedSfixed32List([-1234]); |
||||
msg.setRepeatedSfixed64List([-0x1234567800000000]); |
||||
msg.setRepeatedFloatList([1.5]); |
||||
msg.setRepeatedDoubleList([-1.5]); |
||||
msg.setRepeatedBoolList([true]); |
||||
msg.setRepeatedStringList(['hello world']); |
||||
msg.setRepeatedBytesList([BYTES]); |
||||
submsg = new proto.jspb.test.ForeignMessage(); |
||||
submsg.setC(1000); |
||||
msg.setRepeatedForeignMessageList([submsg]); |
||||
msg.setRepeatedForeignEnumList([proto.jspb.test.Proto3Enum.PROTO3_BAR]); |
||||
|
||||
msg.setOneofString('asdf'); |
||||
|
||||
var serialized = msg.serializeBinary(); |
||||
msg = proto.jspb.test.TestProto3.deserializeBinary(serialized); |
||||
|
||||
assertEquals(msg.getOptionalInt32(), -42); |
||||
assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000); |
||||
assertEquals(msg.getOptionalUint32(), 0x80000000); |
||||
assertEquals(msg.getOptionalUint64(), 0xf000000000000000); |
||||
assertEquals(msg.getOptionalSint32(), -100); |
||||
assertEquals(msg.getOptionalSint64(), -0x8000000000000000); |
||||
assertEquals(msg.getOptionalFixed32(), 1234); |
||||
assertEquals(msg.getOptionalFixed64(), 0x1234567800000000); |
||||
assertEquals(msg.getOptionalSfixed32(), -1234); |
||||
assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000); |
||||
assertEquals(msg.getOptionalFloat(), 1.5); |
||||
assertEquals(msg.getOptionalDouble(), -1.5); |
||||
assertEquals(msg.getOptionalBool(), true); |
||||
assertEquals(msg.getOptionalString(), 'hello world'); |
||||
assertEquals(true, bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
assertEquals(msg.getOptionalForeignMessage().getC(), 16); |
||||
assertEquals(msg.getOptionalForeignEnum(), |
||||
proto.jspb.test.Proto3Enum.PROTO3_BAR); |
||||
|
||||
assertElementsEquals(msg.getRepeatedInt32List(), [-42]); |
||||
assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]); |
||||
assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]); |
||||
assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]); |
||||
assertElementsEquals(msg.getRepeatedSint32List(), [-100]); |
||||
assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]); |
||||
assertElementsEquals(msg.getRepeatedFixed32List(), [1234]); |
||||
assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]); |
||||
assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]); |
||||
assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]); |
||||
assertElementsEquals(msg.getRepeatedFloatList(), [1.5]); |
||||
assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]); |
||||
assertElementsEquals(msg.getRepeatedBoolList(), [true]); |
||||
assertElementsEquals(msg.getRepeatedStringList(), ['hello world']); |
||||
assertEquals(msg.getRepeatedBytesList().length, 1); |
||||
assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], BYTES)); |
||||
assertEquals(msg.getRepeatedForeignMessageList().length, 1); |
||||
assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000); |
||||
assertElementsEquals(msg.getRepeatedForeignEnumList(), |
||||
[proto.jspb.test.Proto3Enum.PROTO3_BAR]); |
||||
|
||||
assertEquals(msg.getOneofString(), 'asdf'); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Test that oneofs continue to have a notion of field presence. |
||||
*/ |
||||
it('testOneofs', function() { |
||||
var msg = new proto.jspb.test.TestProto3(); |
||||
|
||||
assertEquals(msg.getOneofUint32(), 0); |
||||
assertEquals(msg.getOneofForeignMessage(), undefined); |
||||
assertEquals(msg.getOneofString(), ''); |
||||
assertEquals(msg.getOneofBytes(), ''); |
||||
assertFalse(msg.hasOneofUint32()); |
||||
assertFalse(msg.hasOneofString()); |
||||
assertFalse(msg.hasOneofBytes()); |
||||
|
||||
msg.setOneofUint32(42); |
||||
assertEquals(msg.getOneofUint32(), 42); |
||||
assertEquals(msg.getOneofForeignMessage(), undefined); |
||||
assertEquals(msg.getOneofString(), ''); |
||||
assertEquals(msg.getOneofBytes(), ''); |
||||
assertTrue(msg.hasOneofUint32()); |
||||
assertFalse(msg.hasOneofString()); |
||||
assertFalse(msg.hasOneofBytes()); |
||||
|
||||
|
||||
var submsg = new proto.jspb.test.ForeignMessage(); |
||||
msg.setOneofForeignMessage(submsg); |
||||
assertEquals(msg.getOneofUint32(), 0); |
||||
assertEquals(msg.getOneofForeignMessage(), submsg); |
||||
assertEquals(msg.getOneofString(), ''); |
||||
assertEquals(msg.getOneofBytes(), ''); |
||||
assertFalse(msg.hasOneofUint32()); |
||||
assertFalse(msg.hasOneofString()); |
||||
assertFalse(msg.hasOneofBytes()); |
||||
|
||||
msg.setOneofString('hello'); |
||||
assertEquals(msg.getOneofUint32(), 0); |
||||
assertEquals(msg.getOneofForeignMessage(), undefined); |
||||
assertEquals(msg.getOneofString(), 'hello'); |
||||
assertEquals(msg.getOneofBytes(), ''); |
||||
assertFalse(msg.hasOneofUint32()); |
||||
assertTrue(msg.hasOneofString()); |
||||
assertFalse(msg.hasOneofBytes()); |
||||
|
||||
msg.setOneofBytes(goog.crypt.base64.encodeString('\u00FF\u00FF')); |
||||
assertEquals(msg.getOneofUint32(), 0); |
||||
assertEquals(msg.getOneofForeignMessage(), undefined); |
||||
assertEquals(msg.getOneofString(), ''); |
||||
assertEquals(msg.getOneofBytes_asB64(), |
||||
goog.crypt.base64.encodeString('\u00FF\u00FF')); |
||||
assertFalse(msg.hasOneofUint32()); |
||||
assertFalse(msg.hasOneofString()); |
||||
assertTrue(msg.hasOneofBytes()); |
||||
}); |
||||
|
||||
|
||||
/** |
||||
* Test that "default"-valued primitive fields are not emitted on the wire. |
||||
*/ |
||||
it('testNoSerializeDefaults', function() { |
||||
var msg = new proto.jspb.test.TestProto3(); |
||||
|
||||
// Set each primitive to a non-default value, then back to its default, to
|
||||
// ensure that the serialization is actually checking the value and not just
|
||||
// whether it has ever been set.
|
||||
msg.setOptionalInt32(42); |
||||
msg.setOptionalInt32(0); |
||||
msg.setOptionalDouble(3.14); |
||||
msg.setOptionalDouble(0.0); |
||||
msg.setOptionalBool(true); |
||||
msg.setOptionalBool(false); |
||||
msg.setOptionalString('hello world'); |
||||
msg.setOptionalString(''); |
||||
msg.setOptionalBytes(goog.crypt.base64.encodeString('\u00FF\u00FF')); |
||||
msg.setOptionalBytes(''); |
||||
msg.setOptionalForeignMessage(new proto.jspb.test.ForeignMessage()); |
||||
msg.setOptionalForeignMessage(null); |
||||
msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR); |
||||
msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO); |
||||
msg.setOneofUint32(32); |
||||
msg.clearOneofUint32(); |
||||
|
||||
|
||||
var serialized = msg.serializeBinary(); |
||||
assertEquals(0, serialized.length); |
||||
}); |
||||
|
||||
/** |
||||
* Test that base64 string and Uint8Array are interchangeable in bytes fields. |
||||
*/ |
||||
it('testBytesFieldsInterop', function() { |
||||
var msg = new proto.jspb.test.TestProto3(); |
||||
// Set as a base64 string and check all the getters work.
|
||||
msg.setOptionalBytes(BYTES_B64); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
// Test binary serialize round trip doesn't break it.
|
||||
msg = proto.jspb.test.TestProto3.deserializeBinary(msg.serializeBinary()); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
msg = new proto.jspb.test.TestProto3(); |
||||
// Set as a Uint8Array and check all the getters work.
|
||||
msg.setOptionalBytes(BYTES); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
||||
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
||||
|
||||
}); |
||||
}); |
@ -0,0 +1,89 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
import "testbinary.proto"; |
||||
|
||||
package jspb.test; |
||||
|
||||
message TestProto3 { |
||||
int32 optional_int32 = 1; |
||||
int64 optional_int64 = 2; |
||||
uint32 optional_uint32 = 3; |
||||
uint64 optional_uint64 = 4; |
||||
sint32 optional_sint32 = 5; |
||||
sint64 optional_sint64 = 6; |
||||
fixed32 optional_fixed32 = 7; |
||||
fixed64 optional_fixed64 = 8; |
||||
sfixed32 optional_sfixed32 = 9; |
||||
sfixed64 optional_sfixed64 = 10; |
||||
float optional_float = 11; |
||||
double optional_double = 12; |
||||
bool optional_bool = 13; |
||||
string optional_string = 14; |
||||
bytes optional_bytes = 15; |
||||
|
||||
ForeignMessage optional_foreign_message = 19; |
||||
Proto3Enum optional_foreign_enum = 22; |
||||
|
||||
repeated int32 repeated_int32 = 31; |
||||
repeated int64 repeated_int64 = 32; |
||||
repeated uint32 repeated_uint32 = 33; |
||||
repeated uint64 repeated_uint64 = 34; |
||||
repeated sint32 repeated_sint32 = 35; |
||||
repeated sint64 repeated_sint64 = 36; |
||||
repeated fixed32 repeated_fixed32 = 37; |
||||
repeated fixed64 repeated_fixed64 = 38; |
||||
repeated sfixed32 repeated_sfixed32 = 39; |
||||
repeated sfixed64 repeated_sfixed64 = 40; |
||||
repeated float repeated_float = 41; |
||||
repeated double repeated_double = 42; |
||||
repeated bool repeated_bool = 43; |
||||
repeated string repeated_string = 44; |
||||
repeated bytes repeated_bytes = 45; |
||||
|
||||
repeated ForeignMessage repeated_foreign_message = 49; |
||||
repeated Proto3Enum repeated_foreign_enum = 52; |
||||
|
||||
|
||||
oneof oneof_field { |
||||
uint32 oneof_uint32 = 111; |
||||
ForeignMessage oneof_foreign_message = 112; |
||||
string oneof_string = 113; |
||||
bytes oneof_bytes = 114; |
||||
} |
||||
} |
||||
|
||||
enum Proto3Enum { |
||||
PROTO3_FOO = 0; |
||||
PROTO3_BAR = 1; |
||||
PROTO3_BAZ = 2; |
||||
} |
@ -0,0 +1,262 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
// Author: mwr@google.com (Mark Rawling) |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
import "google/protobuf/descriptor.proto"; |
||||
|
||||
package jspb.test; |
||||
|
||||
message Empty { |
||||
} |
||||
|
||||
enum OuterEnum { |
||||
FOO = 1; |
||||
BAR = 2; |
||||
} |
||||
|
||||
message EnumContainer { |
||||
optional OuterEnum outer_enum = 1; |
||||
} |
||||
|
||||
message Simple1 { |
||||
required string a_string = 1; |
||||
repeated string a_repeated_string = 2; |
||||
optional bool a_boolean = 3; |
||||
} |
||||
|
||||
// A message that differs from Simple1 only by name |
||||
message Simple2 { |
||||
required string a_string = 1; |
||||
repeated string a_repeated_string = 2; |
||||
} |
||||
|
||||
message SpecialCases { |
||||
required string normal = 1; |
||||
// Examples of Js reserved names that are converted to pb_<name>. |
||||
required string default = 2; |
||||
required string function = 3; |
||||
required string var = 4; |
||||
} |
||||
|
||||
message OptionalFields { |
||||
message Nested { |
||||
optional int32 an_int = 1; |
||||
} |
||||
optional string a_string = 1; |
||||
required bool a_bool = 2; |
||||
optional Nested a_nested_message = 3; |
||||
repeated Nested a_repeated_message = 4; |
||||
repeated string a_repeated_string = 5; |
||||
} |
||||
|
||||
message HasExtensions { |
||||
optional string str1 = 1; |
||||
optional string str2 = 2; |
||||
optional string str3 = 3; |
||||
extensions 10 to max; |
||||
} |
||||
|
||||
message Complex { |
||||
message Nested { |
||||
required int32 an_int = 2; |
||||
} |
||||
required string a_string = 1; |
||||
required bool an_out_of_order_bool = 9; |
||||
optional Nested a_nested_message = 4; |
||||
repeated Nested a_repeated_message = 5; |
||||
repeated string a_repeated_string = 7; |
||||
} |
||||
|
||||
message OuterMessage { |
||||
// Make sure this doesn't conflict with the other Complex message. |
||||
message Complex { |
||||
optional int32 inner_complex_field = 1; |
||||
} |
||||
} |
||||
|
||||
message IsExtension { |
||||
extend HasExtensions { |
||||
optional IsExtension ext_field = 100; |
||||
} |
||||
optional string ext1 = 1; |
||||
|
||||
// Extensions of proto2 Descriptor messages will be ignored. |
||||
extend google.protobuf.EnumOptions { |
||||
optional string simple_option = 42113038; |
||||
} |
||||
} |
||||
|
||||
message IndirectExtension { |
||||
extend HasExtensions { |
||||
optional Simple1 simple = 101; |
||||
optional string str = 102; |
||||
repeated string repeated_str = 103; |
||||
repeated Simple1 repeated_simple = 104; |
||||
} |
||||
} |
||||
|
||||
extend HasExtensions { |
||||
optional Simple1 simple1 = 105; |
||||
} |
||||
|
||||
message DefaultValues { |
||||
enum Enum { |
||||
E1 = 13; |
||||
E2 = 77; |
||||
} |
||||
optional string string_field = 1 [default="default<>\'\"abc"]; |
||||
optional bool bool_field = 2 [default=true]; |
||||
optional int64 int_field = 3 [default=11]; |
||||
optional Enum enum_field = 4 [default=E1]; |
||||
optional string empty_field = 6 [default=""]; |
||||
optional bytes bytes_field = 8 [default="moo"]; // Base64 encoding is "bW9v" |
||||
} |
||||
|
||||
message FloatingPointFields { |
||||
optional float optional_float_field = 1; |
||||
required float required_float_field = 2; |
||||
repeated float repeated_float_field = 3; |
||||
optional float default_float_field = 4 [default = 2.0]; |
||||
optional double optional_double_field = 5; |
||||
required double required_double_field = 6; |
||||
repeated double repeated_double_field = 7; |
||||
optional double default_double_field = 8 [default = 2.0]; |
||||
} |
||||
|
||||
message TestClone { |
||||
optional string str = 1; |
||||
optional Simple1 simple1 = 3; |
||||
repeated Simple1 simple2 = 5; |
||||
optional bytes bytes_field = 6; |
||||
optional string unused = 7; |
||||
extensions 10 to max; |
||||
} |
||||
|
||||
message CloneExtension { |
||||
extend TestClone { |
||||
optional CloneExtension ext_field = 100; |
||||
} |
||||
optional string ext = 2; |
||||
} |
||||
|
||||
message TestGroup { |
||||
repeated group RepeatedGroup = 1 { |
||||
required string id = 1; |
||||
repeated bool some_bool = 2; |
||||
} |
||||
required group RequiredGroup = 2 { |
||||
required string id = 1; |
||||
} |
||||
optional group OptionalGroup = 3 { |
||||
required string id = 1; |
||||
} |
||||
optional string id = 4; |
||||
required Simple2 required_simple = 5; |
||||
optional Simple2 optional_simple = 6; |
||||
} |
||||
|
||||
message TestGroup1 { |
||||
optional TestGroup.RepeatedGroup group = 1; |
||||
} |
||||
|
||||
message TestReservedNames { |
||||
optional int32 extension = 1; |
||||
extensions 10 to max; |
||||
} |
||||
|
||||
message TestReservedNamesExtension { |
||||
extend TestReservedNames { |
||||
optional int32 foo = 10; |
||||
} |
||||
} |
||||
|
||||
message TestMessageWithOneof { |
||||
|
||||
oneof partial_oneof { |
||||
string pone = 3; |
||||
string pthree = 5; |
||||
} |
||||
|
||||
oneof recursive_oneof { |
||||
TestMessageWithOneof rone = 6; |
||||
string rtwo = 7; |
||||
} |
||||
|
||||
optional bool normal_field = 8; |
||||
repeated string repeated_field = 9; |
||||
|
||||
oneof default_oneof_a { |
||||
int32 aone = 10 [default = 1234]; |
||||
int32 atwo = 11; |
||||
} |
||||
|
||||
oneof default_oneof_b { |
||||
int32 bone = 12; |
||||
int32 btwo = 13 [default = 1234]; |
||||
} |
||||
} |
||||
|
||||
message TestEndsWithBytes { |
||||
optional int32 value = 1; |
||||
optional bytes data = 2; |
||||
} |
||||
|
||||
message TestMapFieldsNoBinary { |
||||
map<string, string> map_string_string = 1; |
||||
map<string, int32> map_string_int32 = 2; |
||||
map<string, int64> map_string_int64 = 3; |
||||
map<string, bool> map_string_bool = 4; |
||||
map<string, double> map_string_double = 5; |
||||
map<string, MapValueEnumNoBinary> map_string_enum = 6; |
||||
map<string, MapValueMessageNoBinary> map_string_msg = 7; |
||||
|
||||
map<int32, string> map_int32_string = 8; |
||||
map<int64, string> map_int64_string = 9; |
||||
map<bool, string> map_bool_string = 10; |
||||
|
||||
optional TestMapFieldsNoBinary test_map_fields = 11; |
||||
map<string, TestMapFieldsNoBinary> map_string_testmapfields = 12; |
||||
} |
||||
|
||||
enum MapValueEnumNoBinary { |
||||
MAP_VALUE_FOO_NOBINARY = 0; |
||||
MAP_VALUE_BAR_NOBINARY = 1; |
||||
MAP_VALUE_BAZ_NOBINARY = 2; |
||||
} |
||||
|
||||
message MapValueMessageNoBinary { |
||||
optional int32 foo = 1; |
||||
} |
@ -0,0 +1,54 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.test; |
||||
|
||||
message TestExtensionsMessage { |
||||
optional int32 intfield = 1; |
||||
extensions 100 to max; |
||||
} |
||||
|
||||
message ExtensionMessage { |
||||
extend TestExtensionsMessage { |
||||
optional ExtensionMessage ext_field = 100; |
||||
} |
||||
optional string ext1 = 1; |
||||
} |
||||
|
||||
// Floating extensions are only supported when generating a _lib.js library. |
||||
extend TestExtensionsMessage { |
||||
optional ExtensionMessage floating_msg_field = 101; |
||||
optional string floating_str_field = 102; |
||||
} |
@ -0,0 +1,53 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.exttest; |
||||
|
||||
message TestExtensionsMessage { |
||||
optional int32 intfield = 1; |
||||
extensions 100 to max; |
||||
} |
||||
|
||||
message ExtensionMessage { |
||||
extend TestExtensionsMessage { |
||||
optional ExtensionMessage ext_field = 100; |
||||
} |
||||
optional string ext1 = 1; |
||||
} |
||||
|
||||
extend TestExtensionsMessage { |
||||
optional ExtensionMessage floating_msg_field = 101; |
||||
optional string floating_str_field = 102; |
||||
} |
@ -0,0 +1,42 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.exttest; |
||||
|
||||
import "test3.proto"; |
||||
|
||||
extend TestExtensionsMessage { |
||||
optional ExtensionMessage floating_msg_field_two = 103; |
||||
} |
@ -0,0 +1,44 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
option java_package = "com.google.apps.jspb.proto"; |
||||
option java_multiple_files = true; |
||||
|
||||
package jspb.exttest.beta; |
||||
|
||||
message TestBetaExtensionsMessage { |
||||
extensions 100 to max; |
||||
} |
||||
|
||||
extend TestBetaExtensionsMessage { |
||||
optional string floating_str_field = 101; |
||||
} |
@ -0,0 +1,212 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
// LINT: ALLOW_GROUPS |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
|
||||
package jspb.test; |
||||
|
||||
// These types are borrowed from `unittest.proto` in the protobuf tree. We want |
||||
// to ensure that the binary-format support will handle all field types |
||||
// properly. |
||||
message TestAllTypes { |
||||
optional int32 optional_int32 = 1; |
||||
optional int64 optional_int64 = 2; |
||||
optional uint32 optional_uint32 = 3; |
||||
optional uint64 optional_uint64 = 4; |
||||
optional sint32 optional_sint32 = 5; |
||||
optional sint64 optional_sint64 = 6; |
||||
optional fixed32 optional_fixed32 = 7; |
||||
optional fixed64 optional_fixed64 = 8; |
||||
optional sfixed32 optional_sfixed32 = 9; |
||||
optional sfixed64 optional_sfixed64 = 10; |
||||
optional float optional_float = 11; |
||||
optional double optional_double = 12; |
||||
optional bool optional_bool = 13; |
||||
optional string optional_string = 14; |
||||
optional bytes optional_bytes = 15; |
||||
optional group OptionalGroup = 16 { |
||||
optional int32 a = 17; |
||||
} |
||||
|
||||
optional ForeignMessage optional_foreign_message = 19; |
||||
optional ForeignEnum optional_foreign_enum = 22; |
||||
|
||||
// Repeated |
||||
repeated int32 repeated_int32 = 31; |
||||
repeated int64 repeated_int64 = 32; |
||||
repeated uint32 repeated_uint32 = 33; |
||||
repeated uint64 repeated_uint64 = 34; |
||||
repeated sint32 repeated_sint32 = 35; |
||||
repeated sint64 repeated_sint64 = 36; |
||||
repeated fixed32 repeated_fixed32 = 37; |
||||
repeated fixed64 repeated_fixed64 = 38; |
||||
repeated sfixed32 repeated_sfixed32 = 39; |
||||
repeated sfixed64 repeated_sfixed64 = 40; |
||||
repeated float repeated_float = 41; |
||||
repeated double repeated_double = 42; |
||||
repeated bool repeated_bool = 43; |
||||
repeated string repeated_string = 44; |
||||
repeated bytes repeated_bytes = 45; |
||||
|
||||
repeated group RepeatedGroup = 46 { |
||||
optional int32 a = 47; |
||||
} |
||||
|
||||
repeated ForeignMessage repeated_foreign_message = 49; |
||||
repeated ForeignEnum repeated_foreign_enum = 52; |
||||
|
||||
// Packed repeated |
||||
repeated int32 packed_repeated_int32 = 61 [packed=true]; |
||||
repeated int64 packed_repeated_int64 = 62 [packed=true]; |
||||
repeated uint32 packed_repeated_uint32 = 63 [packed=true]; |
||||
repeated uint64 packed_repeated_uint64 = 64 [packed=true]; |
||||
repeated sint32 packed_repeated_sint32 = 65 [packed=true]; |
||||
repeated sint64 packed_repeated_sint64 = 66 [packed=true]; |
||||
repeated fixed32 packed_repeated_fixed32 = 67 [packed=true]; |
||||
repeated fixed64 packed_repeated_fixed64 = 68 [packed=true]; |
||||
repeated sfixed32 packed_repeated_sfixed32 = 69 [packed=true]; |
||||
repeated sfixed64 packed_repeated_sfixed64 = 70 [packed=true]; |
||||
repeated float packed_repeated_float = 71 [packed=true]; |
||||
repeated double packed_repeated_double = 72 [packed=true]; |
||||
repeated bool packed_repeated_bool = 73 [packed=true]; |
||||
|
||||
oneof oneof_field { |
||||
uint32 oneof_uint32 = 111; |
||||
ForeignMessage oneof_foreign_message = 112; |
||||
string oneof_string = 113; |
||||
bytes oneof_bytes = 114; |
||||
} |
||||
|
||||
} |
||||
|
||||
message ForeignMessage { |
||||
optional int32 c = 1; |
||||
} |
||||
|
||||
enum ForeignEnum { |
||||
FOREIGN_FOO = 4; |
||||
FOREIGN_BAR = 5; |
||||
FOREIGN_BAZ = 6; |
||||
} |
||||
|
||||
message TestExtendable { |
||||
extensions 1 to max; |
||||
} |
||||
|
||||
message ExtendsWithMessage { |
||||
extend TestExtendable { |
||||
optional ExtendsWithMessage optional_extension = 19; |
||||
repeated ExtendsWithMessage repeated_extension = 49; |
||||
} |
||||
optional int32 foo = 1; |
||||
} |
||||
|
||||
extend TestExtendable { |
||||
optional int32 extend_optional_int32 = 1; |
||||
optional int64 extend_optional_int64 = 2; |
||||
optional uint32 extend_optional_uint32 = 3; |
||||
optional uint64 extend_optional_uint64 = 4; |
||||
optional sint32 extend_optional_sint32 = 5; |
||||
optional sint64 extend_optional_sint64 = 6; |
||||
optional fixed32 extend_optional_fixed32 = 7; |
||||
optional fixed64 extend_optional_fixed64 = 8; |
||||
optional sfixed32 extend_optional_sfixed32 = 9; |
||||
optional sfixed64 extend_optional_sfixed64 = 10; |
||||
optional float extend_optional_float = 11; |
||||
optional double extend_optional_double = 12; |
||||
optional bool extend_optional_bool = 13; |
||||
optional string extend_optional_string = 14; |
||||
optional bytes extend_optional_bytes = 15; |
||||
optional ForeignEnum extend_optional_foreign_enum = 22; |
||||
|
||||
repeated int32 extend_repeated_int32 = 31; |
||||
repeated int64 extend_repeated_int64 = 32; |
||||
repeated uint32 extend_repeated_uint32 = 33; |
||||
repeated uint64 extend_repeated_uint64 = 34; |
||||
repeated sint32 extend_repeated_sint32 = 35; |
||||
repeated sint64 extend_repeated_sint64 = 36; |
||||
repeated fixed32 extend_repeated_fixed32 = 37; |
||||
repeated fixed64 extend_repeated_fixed64 = 38; |
||||
repeated sfixed32 extend_repeated_sfixed32 = 39; |
||||
repeated sfixed64 extend_repeated_sfixed64 = 40; |
||||
repeated float extend_repeated_float = 41; |
||||
repeated double extend_repeated_double = 42; |
||||
repeated bool extend_repeated_bool = 43; |
||||
repeated string extend_repeated_string = 44; |
||||
repeated bytes extend_repeated_bytes = 45; |
||||
repeated ForeignEnum extend_repeated_foreign_enum = 52; |
||||
|
||||
repeated int32 extend_packed_repeated_int32 = 61 [packed=true]; |
||||
repeated int64 extend_packed_repeated_int64 = 62 [packed=true]; |
||||
repeated uint32 extend_packed_repeated_uint32 = 63 [packed=true]; |
||||
repeated uint64 extend_packed_repeated_uint64 = 64 [packed=true]; |
||||
repeated sint32 extend_packed_repeated_sint32 = 65 [packed=true]; |
||||
repeated sint64 extend_packed_repeated_sint64 = 66 [packed=true]; |
||||
repeated fixed32 extend_packed_repeated_fixed32 = 67 [packed=true]; |
||||
repeated fixed64 extend_packed_repeated_fixed64 = 68 [packed=true]; |
||||
repeated sfixed32 extend_packed_repeated_sfixed32 = 69 [packed=true]; |
||||
repeated sfixed64 extend_packed_repeated_sfixed64 = 70 [packed=true]; |
||||
repeated float extend_packed_repeated_float = 71 [packed=true]; |
||||
repeated double extend_packed_repeated_double = 72 [packed=true]; |
||||
repeated bool extend_packed_repeated_bool = 73 [packed=true]; |
||||
repeated ForeignEnum extend_packed_repeated_foreign_enum = 82 |
||||
[packed=true]; |
||||
|
||||
} |
||||
|
||||
message TestMapFields { |
||||
map<string, string> map_string_string = 1; |
||||
map<string, int32> map_string_int32 = 2; |
||||
map<string, int64> map_string_int64 = 3; |
||||
map<string, bool> map_string_bool = 4; |
||||
map<string, double> map_string_double = 5; |
||||
map<string, MapValueEnum> map_string_enum = 6; |
||||
map<string, MapValueMessage> map_string_msg = 7; |
||||
|
||||
map<int32, string> map_int32_string = 8; |
||||
map<int64, string> map_int64_string = 9; |
||||
map<bool, string> map_bool_string = 10; |
||||
|
||||
optional TestMapFields test_map_fields = 11; |
||||
map<string, TestMapFields> map_string_testmapfields = 12; |
||||
} |
||||
|
||||
enum MapValueEnum { |
||||
MAP_VALUE_FOO = 0; |
||||
MAP_VALUE_BAR = 1; |
||||
MAP_VALUE_BAZ = 2; |
||||
} |
||||
|
||||
message MapValueMessage { |
||||
optional int32 foo = 1; |
||||
} |
@ -0,0 +1,34 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
package javatests.com.google.apps.jspb; |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue