Merge tag 'refs/tags/sync-piper' into sync-stage
This commit is contained in:
commit
09831d5bfe
@ -31,14 +31,21 @@
|
||||
package com.google.protobuf;
|
||||
|
||||
final class Android {
|
||||
private Android() {
|
||||
}
|
||||
|
||||
// Set to true in lite_proguard_android.pgcfg.
|
||||
@SuppressWarnings("ConstantField")
|
||||
private static boolean ASSUME_ANDROID;
|
||||
|
||||
private static final Class<?> MEMORY_CLASS = getClassForName("libcore.io.Memory");
|
||||
|
||||
private static final boolean IS_ROBOLECTRIC =
|
||||
getClassForName("org.robolectric.Robolectric") != null;
|
||||
!ASSUME_ANDROID && getClassForName("org.robolectric.Robolectric") != null;
|
||||
|
||||
/** Returns {@code true} if running on an Android device. */
|
||||
static boolean isOnAndroidDevice() {
|
||||
return MEMORY_CLASS != null && !IS_ROBOLECTRIC;
|
||||
return ASSUME_ANDROID || (MEMORY_CLASS != null && !IS_ROBOLECTRIC);
|
||||
}
|
||||
|
||||
/** Returns the memory class or {@code null} if not on Android device. */
|
||||
|
@ -184,20 +184,20 @@ final class RawMessageInfo implements MessageInfo {
|
||||
int value;
|
||||
try {
|
||||
value = (int) info.charAt(0);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
// This is a fix for issues
|
||||
// that error out on a subset of phones on charAt(0) with an index out of bounds exception.
|
||||
char[] infoChars = info.toCharArray();
|
||||
info = new String(infoChars);
|
||||
try {
|
||||
value = (int) info.charAt(0);
|
||||
} catch (ArrayIndexOutOfBoundsException e2) {
|
||||
} catch (StringIndexOutOfBoundsException e2) {
|
||||
try {
|
||||
char[] infoChars2 = new char[info.length()];
|
||||
info.getChars(0, info.length(), infoChars2, 0);
|
||||
info = new String(infoChars2);
|
||||
value = (int) info.charAt(0);
|
||||
} catch (ArrayIndexOutOfBoundsException e3) {
|
||||
} catch (StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e3) {
|
||||
throw new IllegalStateException(
|
||||
String.format(
|
||||
"Failed parsing '%s' with charArray.length of %d", info, infoChars.length),
|
||||
|
@ -1,3 +1,8 @@
|
||||
|
||||
# Skip runtime check for isOnAndroidDevice().
|
||||
# One line to make it easy to remove with sed.
|
||||
-assumevalues class com.google.protobuf.Android { static boolean ASSUME_ANDROID return true; }
|
||||
|
||||
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
|
||||
<fields>;
|
||||
}
|
||||
|
@ -46,7 +46,8 @@ goog.require('jspb.BinaryConstants');
|
||||
goog.require('jspb.BinaryDecoder');
|
||||
goog.require('jspb.BinaryReader');
|
||||
goog.require('jspb.BinaryWriter');
|
||||
|
||||
goog.require('jspb.utils');
|
||||
goog.requireType('jspb.BinaryMessage');
|
||||
|
||||
|
||||
describe('binaryReaderTest', function() {
|
||||
@ -55,7 +56,7 @@ describe('binaryReaderTest', function() {
|
||||
*/
|
||||
it('testInstanceCaches', /** @suppress {visibility} */ function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
writer.writeMessage(1, dummyMessage, goog.nullFunction);
|
||||
writer.writeMessage(2, dummyMessage, goog.nullFunction);
|
||||
|
||||
@ -135,7 +136,7 @@ describe('binaryReaderTest', function() {
|
||||
// Calling readMessage on a non-delimited field should trigger an
|
||||
// assertion.
|
||||
var reader = jspb.BinaryReader.alloc([8, 1]);
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
reader.nextField();
|
||||
assertThrows(function() {
|
||||
reader.readMessage(dummyMessage, goog.nullFunction);
|
||||
@ -144,47 +145,91 @@ describe('binaryReaderTest', function() {
|
||||
// Reading past the end of the stream should trigger an assertion.
|
||||
reader = jspb.BinaryReader.alloc([9, 1]);
|
||||
reader.nextField();
|
||||
assertThrows(function() {reader.readFixed64()});
|
||||
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()});
|
||||
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()});
|
||||
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()});
|
||||
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.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()});
|
||||
assertThrows(function() {
|
||||
reader.readString()
|
||||
});
|
||||
assertThrows(function() {
|
||||
reader.readBytes()
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -198,8 +243,8 @@ describe('binaryReaderTest', function() {
|
||||
* @private
|
||||
* @suppress {missingProperties}
|
||||
*/
|
||||
var doTestUnsignedField_ = function(readField,
|
||||
writeField, epsilon, upperLimit, filter) {
|
||||
var doTestUnsignedField_ = function(
|
||||
readField, writeField, epsilon, upperLimit, filter) {
|
||||
assertNotNull(readField);
|
||||
assertNotNull(writeField);
|
||||
|
||||
@ -250,8 +295,8 @@ describe('binaryReaderTest', function() {
|
||||
* @private
|
||||
* @suppress {missingProperties}
|
||||
*/
|
||||
var doTestSignedField_ = function(readField,
|
||||
writeField, epsilon, lowerLimit, upperLimit, filter) {
|
||||
var doTestSignedField_ = function(
|
||||
readField, writeField, epsilon, lowerLimit, upperLimit, filter) {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
|
||||
// Encode zero and limits.
|
||||
@ -267,20 +312,14 @@ describe('binaryReaderTest', function() {
|
||||
for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) {
|
||||
var val = filter(cursor);
|
||||
writeField.call(writer, 6, val);
|
||||
inputValues.push({
|
||||
fieldNumber: 6,
|
||||
value: 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
|
||||
});
|
||||
inputValues.push({fieldNumber: 7, value: val});
|
||||
}
|
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
|
||||
@ -327,33 +366,34 @@ describe('binaryReaderTest', function() {
|
||||
assertNotUndefined(jspb.BinaryWriter.prototype.writeBool);
|
||||
doTestUnsignedField_(
|
||||
jspb.BinaryReader.prototype.readUint32,
|
||||
jspb.BinaryWriter.prototype.writeUint32,
|
||||
1, Math.pow(2, 32) - 1, Math.round);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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; });
|
||||
jspb.BinaryWriter.prototype.writeBool, 1, 1, function(x) {
|
||||
return !!x;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -387,24 +427,22 @@ describe('binaryReaderTest', function() {
|
||||
// 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');
|
||||
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');
|
||||
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');
|
||||
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');
|
||||
jspb.BinaryReader.prototype.readSint64, -6,
|
||||
'08 8B 80 80 80 80 80 80 80 80 00');
|
||||
});
|
||||
|
||||
/**
|
||||
@ -440,27 +478,15 @@ describe('binaryReaderTest', function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
|
||||
var testSignedData = [
|
||||
'2730538252207801776',
|
||||
'-2688470994844604560',
|
||||
'3398529779486536359',
|
||||
'3568577411627971000',
|
||||
'272477188847484900',
|
||||
'-6649058714086158188',
|
||||
'-7695254765712060806',
|
||||
'-4525541438037104029',
|
||||
'-4993706538836508568',
|
||||
'2730538252207801776', '-2688470994844604560', '3398529779486536359',
|
||||
'3568577411627971000', '272477188847484900', '-6649058714086158188',
|
||||
'-7695254765712060806', '-4525541438037104029', '-4993706538836508568',
|
||||
'4990160321893729138'
|
||||
];
|
||||
var testUnsignedData = [
|
||||
'7822732630241694882',
|
||||
'6753602971916687352',
|
||||
'2399935075244442116',
|
||||
'8724292567325338867',
|
||||
'16948784802625696584',
|
||||
'4136275908516066934',
|
||||
'3575388346793700364',
|
||||
'5167142028379259461',
|
||||
'1557573948689737699',
|
||||
'7822732630241694882', '6753602971916687352', '2399935075244442116',
|
||||
'8724292567325338867', '16948784802625696584', '4136275908516066934',
|
||||
'3575388346793700364', '5167142028379259461', '1557573948689737699',
|
||||
'17100725280812548567'
|
||||
];
|
||||
|
||||
@ -488,13 +514,13 @@ describe('binaryReaderTest', function() {
|
||||
it('testZigzagFields', function() {
|
||||
doTestSignedField_(
|
||||
jspb.BinaryReader.prototype.readSint32,
|
||||
jspb.BinaryWriter.prototype.writeSint32,
|
||||
1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round);
|
||||
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);
|
||||
jspb.BinaryWriter.prototype.writeSint64, 1, -Math.pow(2, 63),
|
||||
Math.pow(2, 63) - 513, Math.round);
|
||||
|
||||
doTestSignedField_(
|
||||
jspb.BinaryReader.prototype.readSintHash64,
|
||||
@ -509,23 +535,23 @@ describe('binaryReaderTest', function() {
|
||||
it('testFixedFields', function() {
|
||||
doTestUnsignedField_(
|
||||
jspb.BinaryReader.prototype.readFixed32,
|
||||
jspb.BinaryWriter.prototype.writeFixed32,
|
||||
1, Math.pow(2, 32) - 1, Math.round);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
jspb.BinaryWriter.prototype.writeSfixed64, 1, -Math.pow(2, 63),
|
||||
Math.pow(2, 63) - 513, Math.round);
|
||||
});
|
||||
|
||||
|
||||
@ -536,18 +562,17 @@ describe('binaryReaderTest', function() {
|
||||
doTestSignedField_(
|
||||
jspb.BinaryReader.prototype.readFloat,
|
||||
jspb.BinaryWriter.prototype.writeFloat,
|
||||
jspb.BinaryConstants.FLOAT32_MIN,
|
||||
-jspb.BinaryConstants.FLOAT32_MAX,
|
||||
jspb.BinaryConstants.FLOAT32_MAX,
|
||||
truncate);
|
||||
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; });
|
||||
-jspb.BinaryConstants.FLOAT64_MIN, jspb.BinaryConstants.FLOAT64_MIN,
|
||||
function(x) {
|
||||
return x;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -614,7 +639,7 @@ describe('binaryReaderTest', function() {
|
||||
*/
|
||||
it('testNesting', function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
writer.writeInt32(1, 100);
|
||||
|
||||
@ -707,7 +732,7 @@ describe('binaryReaderTest', function() {
|
||||
|
||||
// Write a group with a nested group inside.
|
||||
writer.writeInt32(5, sentinel);
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
writer.writeGroup(5, dummyMessage, function() {
|
||||
// Previously the skipGroup implementation was wrong, which only consume
|
||||
// the decoder by nextField. This case is for making the previous
|
||||
@ -726,7 +751,7 @@ describe('binaryReaderTest', function() {
|
||||
writer.writeInt64(84, 42);
|
||||
writer.writeInt64(84, 44);
|
||||
writer.writeBytes(
|
||||
43, [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]);
|
||||
43, [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -875,7 +900,7 @@ describe('binaryReaderTest', function() {
|
||||
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} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
writer.writeMessage(1, dummyMessage, function() {
|
||||
writer.writeMessage(1, dummyMessage, function() {
|
||||
@ -908,7 +933,7 @@ describe('binaryReaderTest', function() {
|
||||
*/
|
||||
it('testReadCallbacks', function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
// Add an int, a submessage, and another int.
|
||||
writer.writeInt32(1, 100);
|
||||
|
@ -44,7 +44,8 @@ goog.require('jspb.BinaryConstants');
|
||||
goog.require('jspb.BinaryReader');
|
||||
goog.require('jspb.BinaryWriter');
|
||||
goog.require('jspb.utils');
|
||||
|
||||
goog.require('goog.crypt.base64');
|
||||
goog.requireType('jspb.BinaryMessage');
|
||||
|
||||
/**
|
||||
* @param {function()} func This function should throw an error when run.
|
||||
@ -61,7 +62,7 @@ describe('binaryWriterTest', function() {
|
||||
it('testWriteErrors', function() {
|
||||
// Submessages with invalid field indices should assert.
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
assertFails(function() {
|
||||
writer.writeMessage(-1, dummyMessage, goog.nullFunction);
|
||||
@ -69,40 +70,82 @@ describe('binaryWriterTest', function() {
|
||||
|
||||
// Writing invalid field indices should assert.
|
||||
writer = new jspb.BinaryWriter();
|
||||
assertFails(function() {writer.writeUint64(-1, 1);});
|
||||
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.writeInt32(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeInt32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeInt64(1, -Infinity);});
|
||||
assertFails(function() {writer.writeInt64(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.writeUint32(1, -1);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeUint32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeUint64(1, -1);});
|
||||
assertFails(function() {writer.writeUint64(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.writeSint32(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeSint32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeSint64(1, -Infinity);});
|
||||
assertFails(function() {writer.writeSint64(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.writeFixed32(1, -1);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeFixed32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeFixed64(1, -1);});
|
||||
assertFails(function() {writer.writeFixed64(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.writeSfixed32(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeSfixed32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeSfixed64(1, -Infinity);});
|
||||
assertFails(function() {writer.writeSfixed64(1, Infinity);});
|
||||
assertFails(function() {
|
||||
writer.writeSfixed64(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeSfixed64(1, Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ goog.require('jspb.BinaryConstants');
|
||||
goog.require('jspb.BinaryDecoder');
|
||||
goog.require('jspb.BinaryReader');
|
||||
goog.require('jspb.BinaryWriter');
|
||||
|
||||
goog.requireType('jspb.BinaryMessage');
|
||||
|
||||
|
||||
describe('binaryReaderTest', function() {
|
||||
@ -55,7 +55,7 @@ describe('binaryReaderTest', function() {
|
||||
*/
|
||||
it('testInstanceCaches', /** @suppress {visibility} */ function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
writer.writeMessage(1, dummyMessage, goog.nullFunction);
|
||||
writer.writeMessage(2, dummyMessage, goog.nullFunction);
|
||||
|
||||
@ -135,7 +135,7 @@ describe('binaryReaderTest', function() {
|
||||
// Calling readMessage on a non-delimited field should trigger an
|
||||
// assertion.
|
||||
var reader = jspb.BinaryReader.alloc([8, 1]);
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
reader.nextField();
|
||||
assertThrows(function() {
|
||||
reader.readMessage(dummyMessage, goog.nullFunction);
|
||||
@ -144,47 +144,91 @@ describe('binaryReaderTest', function() {
|
||||
// Reading past the end of the stream should trigger an assertion.
|
||||
reader = jspb.BinaryReader.alloc([9, 1]);
|
||||
reader.nextField();
|
||||
assertThrows(function() {reader.readFixed64()});
|
||||
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()});
|
||||
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()});
|
||||
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()});
|
||||
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.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()});
|
||||
assertThrows(function() {
|
||||
reader.readString()
|
||||
});
|
||||
assertThrows(function() {
|
||||
reader.readBytes()
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -198,8 +242,8 @@ describe('binaryReaderTest', function() {
|
||||
* @private
|
||||
* @suppress {missingProperties}
|
||||
*/
|
||||
var doTestUnsignedField_ = function(readField,
|
||||
writeField, epsilon, upperLimit, filter) {
|
||||
var doTestUnsignedField_ = function(
|
||||
readField, writeField, epsilon, upperLimit, filter) {
|
||||
assertNotNull(readField);
|
||||
assertNotNull(writeField);
|
||||
|
||||
@ -250,8 +294,8 @@ describe('binaryReaderTest', function() {
|
||||
* @private
|
||||
* @suppress {missingProperties}
|
||||
*/
|
||||
var doTestSignedField_ = function(readField,
|
||||
writeField, epsilon, lowerLimit, upperLimit, filter) {
|
||||
var doTestSignedField_ = function(
|
||||
readField, writeField, epsilon, lowerLimit, upperLimit, filter) {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
|
||||
// Encode zero and limits.
|
||||
@ -267,20 +311,14 @@ describe('binaryReaderTest', function() {
|
||||
for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) {
|
||||
var val = filter(cursor);
|
||||
writeField.call(writer, 6, val);
|
||||
inputValues.push({
|
||||
fieldNumber: 6,
|
||||
value: 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
|
||||
});
|
||||
inputValues.push({fieldNumber: 7, value: val});
|
||||
}
|
||||
|
||||
var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
|
||||
@ -327,33 +365,34 @@ describe('binaryReaderTest', function() {
|
||||
assertNotUndefined(jspb.BinaryWriter.prototype.writeBool);
|
||||
doTestUnsignedField_(
|
||||
jspb.BinaryReader.prototype.readUint32,
|
||||
jspb.BinaryWriter.prototype.writeUint32,
|
||||
1, Math.pow(2, 32) - 1, Math.round);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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; });
|
||||
jspb.BinaryWriter.prototype.writeBool, 1, 1, function(x) {
|
||||
return !!x;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -387,24 +426,22 @@ describe('binaryReaderTest', function() {
|
||||
// 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');
|
||||
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');
|
||||
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');
|
||||
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');
|
||||
jspb.BinaryReader.prototype.readSint64, -6,
|
||||
'08 8B 80 80 80 80 80 80 80 80 00');
|
||||
});
|
||||
|
||||
|
||||
@ -415,27 +452,15 @@ describe('binaryReaderTest', function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
|
||||
var testSignedData = [
|
||||
'2730538252207801776',
|
||||
'-2688470994844604560',
|
||||
'3398529779486536359',
|
||||
'3568577411627971000',
|
||||
'272477188847484900',
|
||||
'-6649058714086158188',
|
||||
'-7695254765712060806',
|
||||
'-4525541438037104029',
|
||||
'-4993706538836508568',
|
||||
'2730538252207801776', '-2688470994844604560', '3398529779486536359',
|
||||
'3568577411627971000', '272477188847484900', '-6649058714086158188',
|
||||
'-7695254765712060806', '-4525541438037104029', '-4993706538836508568',
|
||||
'4990160321893729138'
|
||||
];
|
||||
var testUnsignedData = [
|
||||
'7822732630241694882',
|
||||
'6753602971916687352',
|
||||
'2399935075244442116',
|
||||
'8724292567325338867',
|
||||
'16948784802625696584',
|
||||
'4136275908516066934',
|
||||
'3575388346793700364',
|
||||
'5167142028379259461',
|
||||
'1557573948689737699',
|
||||
'7822732630241694882', '6753602971916687352', '2399935075244442116',
|
||||
'8724292567325338867', '16948784802625696584', '4136275908516066934',
|
||||
'3575388346793700364', '5167142028379259461', '1557573948689737699',
|
||||
'17100725280812548567'
|
||||
];
|
||||
|
||||
@ -463,13 +488,13 @@ describe('binaryReaderTest', function() {
|
||||
it('testZigzagFields', function() {
|
||||
doTestSignedField_(
|
||||
jspb.BinaryReader.prototype.readSint32,
|
||||
jspb.BinaryWriter.prototype.writeSint32,
|
||||
1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round);
|
||||
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);
|
||||
jspb.BinaryWriter.prototype.writeSint64, 1, -Math.pow(2, 63),
|
||||
Math.pow(2, 63) - 513, Math.round);
|
||||
});
|
||||
|
||||
|
||||
@ -479,23 +504,23 @@ describe('binaryReaderTest', function() {
|
||||
it('testFixedFields', function() {
|
||||
doTestUnsignedField_(
|
||||
jspb.BinaryReader.prototype.readFixed32,
|
||||
jspb.BinaryWriter.prototype.writeFixed32,
|
||||
1, Math.pow(2, 32) - 1, Math.round);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
jspb.BinaryWriter.prototype.writeSfixed64, 1, -Math.pow(2, 63),
|
||||
Math.pow(2, 63) - 513, Math.round);
|
||||
});
|
||||
|
||||
|
||||
@ -506,18 +531,17 @@ describe('binaryReaderTest', function() {
|
||||
doTestSignedField_(
|
||||
jspb.BinaryReader.prototype.readFloat,
|
||||
jspb.BinaryWriter.prototype.writeFloat,
|
||||
jspb.BinaryConstants.FLOAT32_MIN,
|
||||
-jspb.BinaryConstants.FLOAT32_MAX,
|
||||
jspb.BinaryConstants.FLOAT32_MAX,
|
||||
truncate);
|
||||
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; });
|
||||
-jspb.BinaryConstants.FLOAT64_MIN, jspb.BinaryConstants.FLOAT64_MIN,
|
||||
function(x) {
|
||||
return x;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -584,7 +608,7 @@ describe('binaryReaderTest', function() {
|
||||
*/
|
||||
it('testNesting', function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
writer.writeInt32(1, 100);
|
||||
|
||||
@ -677,7 +701,7 @@ describe('binaryReaderTest', function() {
|
||||
|
||||
// Write a group with a nested group inside.
|
||||
writer.writeInt32(5, sentinel);
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
writer.writeGroup(5, dummyMessage, function() {
|
||||
writer.writeInt64(42, 42);
|
||||
writer.writeGroup(6, dummyMessage, function() {
|
||||
@ -830,7 +854,7 @@ describe('binaryReaderTest', function() {
|
||||
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} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
writer.writeMessage(1, dummyMessage, function() {
|
||||
writer.writeMessage(1, dummyMessage, function() {
|
||||
@ -863,7 +887,7 @@ describe('binaryReaderTest', function() {
|
||||
*/
|
||||
it('testReadCallbacks', function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
// Add an int, a submessage, and another int.
|
||||
writer.writeInt32(1, 100);
|
||||
|
@ -41,14 +41,14 @@
|
||||
goog.require('goog.crypt');
|
||||
goog.require('goog.testing.asserts');
|
||||
goog.require('jspb.BinaryWriter');
|
||||
|
||||
goog.requireType('jspb.BinaryMessage');
|
||||
|
||||
/**
|
||||
* @param {function()} func This function should throw an error when run.
|
||||
*/
|
||||
function assertFails(func) {
|
||||
var e = assertThrows(func);
|
||||
//assertNotNull(e.toString().match(/Error/));
|
||||
// assertNotNull(e.toString().match(/Error/));
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ describe('binaryWriterTest', function() {
|
||||
it('testWriteErrors', function() {
|
||||
// Submessages with invalid field indices should assert.
|
||||
var writer = new jspb.BinaryWriter();
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
|
||||
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
|
||||
|
||||
assertFails(function() {
|
||||
writer.writeMessage(-1, dummyMessage, goog.nullFunction);
|
||||
@ -67,40 +67,82 @@ describe('binaryWriterTest', function() {
|
||||
|
||||
// Writing invalid field indices should assert.
|
||||
writer = new jspb.BinaryWriter();
|
||||
assertFails(function() {writer.writeUint64(-1, 1);});
|
||||
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.writeInt32(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeInt32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeInt64(1, -Infinity);});
|
||||
assertFails(function() {writer.writeInt64(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.writeUint32(1, -1);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeUint32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeUint64(1, -1);});
|
||||
assertFails(function() {writer.writeUint64(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.writeSint32(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeSint32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeSint64(1, -Infinity);});
|
||||
assertFails(function() {writer.writeSint64(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.writeFixed32(1, -1);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeFixed32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeFixed64(1, -1);});
|
||||
assertFails(function() {writer.writeFixed64(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.writeSfixed32(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeSfixed32(1, Infinity);
|
||||
});
|
||||
|
||||
assertFails(function() {writer.writeSfixed64(1, -Infinity);});
|
||||
assertFails(function() {writer.writeSfixed64(1, Infinity);});
|
||||
assertFails(function() {
|
||||
writer.writeSfixed64(1, -Infinity);
|
||||
});
|
||||
assertFails(function() {
|
||||
writer.writeSfixed64(1, Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@ -40,6 +40,8 @@ goog.require('proto.jspb.test.TestMapFields');
|
||||
goog.require('proto.jspb.test.MapValueMessageNoBinary');
|
||||
goog.require('proto.jspb.test.TestMapFieldsNoBinary');
|
||||
|
||||
goog.requireType('jspb.Map');
|
||||
|
||||
/**
|
||||
* Helper: check that the given map has exactly this set of (sorted) entries.
|
||||
* @param {!jspb.Map} map
|
||||
@ -98,7 +100,9 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
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.getMapInt64StringMap()
|
||||
.set(0x123456789abc, 'c')
|
||||
.set(0xcba987654321, 'd');
|
||||
msg.getMapBoolStringMap().set(false, 'e').set(true, 'f');
|
||||
};
|
||||
|
||||
@ -107,42 +111,24 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
* @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.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']
|
||||
['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);
|
||||
@ -187,10 +173,7 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
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']
|
||||
]);
|
||||
checkMapEquals(m, [['asdf', 'hello world'], ['jkl;', 'key 2']]);
|
||||
m.del('jkl;');
|
||||
assertEquals(m.has('jkl;'), false);
|
||||
assertEquals(m.get('jkl;'), undefined);
|
||||
@ -242,11 +225,11 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
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'
|
||||
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++) {
|
||||
@ -267,11 +250,7 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
*/
|
||||
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 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');
|
||||
@ -279,9 +258,9 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
assertEquals(entries[2][0], 'b');
|
||||
msg.getMapStringStringMap().del('a');
|
||||
assertEquals(entries.length, 3); // not yet sync'd
|
||||
msg.toArray(); // force a sync
|
||||
msg.toArray(); // force a sync
|
||||
assertEquals(entries.length, 2);
|
||||
assertEquals(entries[0][0], 'b'); // now in sorted order
|
||||
assertEquals(entries[0][0], 'b'); // now in sorted order
|
||||
assertEquals(entries[1][0], 'c');
|
||||
|
||||
var a = msg.toArray();
|
||||
@ -290,12 +269,16 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
}
|
||||
|
||||
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");
|
||||
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');
|
||||
});
|
||||
|
@ -67,7 +67,6 @@ goog.require('proto.jspb.test.Simple1');
|
||||
goog.require('proto.jspb.test.Simple2');
|
||||
goog.require('proto.jspb.test.SpecialCases');
|
||||
goog.require('proto.jspb.test.TestClone');
|
||||
goog.require('proto.jspb.test.TestEndsWithBytes');
|
||||
goog.require('proto.jspb.test.TestGroup');
|
||||
goog.require('proto.jspb.test.TestGroup1');
|
||||
goog.require('proto.jspb.test.TestMessageWithOneof');
|
||||
@ -77,7 +76,7 @@ goog.require('proto.jspb.test.TestReservedNamesExtension');
|
||||
// CommonJS-LoadFromFile: test2_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.ExtensionMessage');
|
||||
goog.require('proto.jspb.test.TestExtensionsMessage');
|
||||
|
||||
goog.require('proto.jspb.test.simple1');
|
||||
|
||||
|
||||
|
||||
@ -102,59 +101,59 @@ describe('Message test suite', function() {
|
||||
});
|
||||
|
||||
it('testComplexConversion', function() {
|
||||
var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, true];
|
||||
var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, true];
|
||||
var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , true];
|
||||
var data2 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , true];
|
||||
var foo = new proto.jspb.test.Complex(data1);
|
||||
var bar = new proto.jspb.test.Complex(data2);
|
||||
var result = foo.toObject();
|
||||
assertObjectEquals({
|
||||
aString: 'a',
|
||||
anOutOfOrderBool: true,
|
||||
aNestedMessage: {
|
||||
anInt: 11
|
||||
},
|
||||
aRepeatedMessageList: [{anInt: 22}, {anInt: 33}],
|
||||
aRepeatedStringList: ['s1', 's2']
|
||||
}, result);
|
||||
assertObjectEquals(
|
||||
{
|
||||
aString: 'a',
|
||||
anOutOfOrderBool: true,
|
||||
aNestedMessage: {anInt: 11},
|
||||
aRepeatedMessageList: [{anInt: 22}, {anInt: 33}],
|
||||
aRepeatedStringList: ['s1', 's2']
|
||||
},
|
||||
result);
|
||||
|
||||
// Now test with the jspb instances included.
|
||||
result = foo.toObject(true /* opt_includeInstance */);
|
||||
assertObjectEquals({
|
||||
aString: 'a',
|
||||
anOutOfOrderBool: true,
|
||||
aNestedMessage: {
|
||||
anInt: 11,
|
||||
$jspbMessageInstance: foo.getANestedMessage()
|
||||
},
|
||||
aRepeatedMessageList: [
|
||||
{anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]},
|
||||
{anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]}
|
||||
],
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
$jspbMessageInstance: foo
|
||||
}, result);
|
||||
|
||||
assertObjectEquals(
|
||||
{
|
||||
aString: 'a',
|
||||
anOutOfOrderBool: true,
|
||||
aNestedMessage:
|
||||
{anInt: 11, $jspbMessageInstance: foo.getANestedMessage()},
|
||||
aRepeatedMessageList: [
|
||||
{anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]},
|
||||
{anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]}
|
||||
],
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
$jspbMessageInstance: foo
|
||||
},
|
||||
result);
|
||||
});
|
||||
|
||||
it('testMissingFields', function() {
|
||||
var foo = new proto.jspb.test.Complex([
|
||||
undefined, undefined, undefined, [],
|
||||
undefined, undefined, undefined, undefined]);
|
||||
undefined, undefined, undefined, [], undefined, undefined, undefined,
|
||||
undefined
|
||||
]);
|
||||
var bar = new proto.jspb.test.Complex([
|
||||
undefined, undefined, undefined, [],
|
||||
undefined, undefined, undefined, undefined]);
|
||||
undefined, undefined, undefined, [], undefined, undefined, undefined,
|
||||
undefined
|
||||
]);
|
||||
var result = foo.toObject();
|
||||
assertObjectEquals({
|
||||
aString: undefined,
|
||||
anOutOfOrderBool: undefined,
|
||||
aNestedMessage: {
|
||||
anInt: undefined
|
||||
},
|
||||
// Note: JsPb converts undefined repeated fields to empty arrays.
|
||||
aRepeatedMessageList: [],
|
||||
aRepeatedStringList: []
|
||||
}, result);
|
||||
|
||||
assertObjectEquals(
|
||||
{
|
||||
aString: undefined,
|
||||
anOutOfOrderBool: undefined,
|
||||
aNestedMessage: {anInt: undefined},
|
||||
// Note: JsPb converts undefined repeated fields to empty arrays.
|
||||
aRepeatedMessageList: [],
|
||||
aRepeatedStringList: []
|
||||
},
|
||||
result);
|
||||
});
|
||||
|
||||
it('testNestedComplexMessage', function() {
|
||||
@ -167,20 +166,21 @@ describe('Message test suite', function() {
|
||||
it('testSpecialCases', function() {
|
||||
// Note: Some property names are reserved in JavaScript.
|
||||
// These names are converted to the Js property named pb_<reserved_name>.
|
||||
var special =
|
||||
new proto.jspb.test.SpecialCases(['normal', 'default', 'function',
|
||||
'var']);
|
||||
var special = new proto.jspb.test.SpecialCases(
|
||||
['normal', 'default', 'function', 'var']);
|
||||
var result = special.toObject();
|
||||
assertObjectEquals({
|
||||
normal: 'normal',
|
||||
pb_default: 'default',
|
||||
pb_function: 'function',
|
||||
pb_var: 'var'
|
||||
}, result);
|
||||
assertObjectEquals(
|
||||
{
|
||||
normal: 'normal',
|
||||
pb_default: 'default',
|
||||
pb_function: 'function',
|
||||
pb_var: 'var'
|
||||
},
|
||||
result);
|
||||
});
|
||||
|
||||
it('testDefaultValues', function() {
|
||||
var defaultString = "default<>\'\"abc";
|
||||
var defaultString = 'default<>\'"abc';
|
||||
var response = new proto.jspb.test.DefaultValues();
|
||||
|
||||
// Test toObject
|
||||
@ -244,8 +244,10 @@ describe('Message test suite', function() {
|
||||
|
||||
// Test that clearing the values reverts them to the default state.
|
||||
response = makeDefault(['blah', false, 111, 77]);
|
||||
response.clearStringField(); response.clearBoolField();
|
||||
response.clearIntField(); response.clearEnumField();
|
||||
response.clearStringField();
|
||||
response.clearBoolField();
|
||||
response.clearIntField();
|
||||
response.clearEnumField();
|
||||
assertEquals(defaultString, response.getStringField());
|
||||
assertEquals(true, response.getBoolField());
|
||||
assertEquals(11, response.getIntField());
|
||||
@ -257,8 +259,10 @@ describe('Message test suite', function() {
|
||||
|
||||
// Test that setFoo(null) clears the values.
|
||||
response = makeDefault(['blah', false, 111, 77]);
|
||||
response.setStringField(null); response.setBoolField(null);
|
||||
response.setIntField(undefined); response.setEnumField(undefined);
|
||||
response.setStringField(null);
|
||||
response.setBoolField(null);
|
||||
response.setIntField(undefined);
|
||||
response.setEnumField(undefined);
|
||||
assertEquals(defaultString, response.getStringField());
|
||||
assertEquals(true, response.getBoolField());
|
||||
assertEquals(11, response.getIntField());
|
||||
@ -288,15 +292,15 @@ describe('Message test suite', function() {
|
||||
// but we actually get a sparse array instead. We could use something
|
||||
// like [1,undefined,2] to avoid this, except that this is still
|
||||
// sparse on IE. No comment...
|
||||
var expected = [,,, [], []];
|
||||
var expected = [, , , [], []];
|
||||
expected[0] = expected[1] = expected[2] = undefined;
|
||||
assertObjectEquals(expected, foo.toArray());
|
||||
});
|
||||
|
||||
it('testDifferenceRawObject', /** @suppress {visibility} */ function() {
|
||||
var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]);
|
||||
var p2 = new proto.jspb.test.HasExtensions(['hi', 'what',
|
||||
{1000: 'unique'}]);
|
||||
var p2 =
|
||||
new proto.jspb.test.HasExtensions(['hi', 'what', {1000: 'unique'}]);
|
||||
var diff = /** @type {proto.jspb.test.HasExtensions} */
|
||||
(jspb.Message.difference(p1, p2));
|
||||
assertEquals('', diff.getStr1());
|
||||
@ -310,13 +314,13 @@ describe('Message test suite', function() {
|
||||
assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi'])));
|
||||
assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye'])));
|
||||
var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]);
|
||||
assertTrue(jspb.Message.equals(s1b,
|
||||
new proto.jspb.test.Simple1(['hi', ['hello']])));
|
||||
assertTrue(jspb.Message.equals(s1b,
|
||||
new proto.jspb.test.Simple1(['hi', ['hello', undefined,
|
||||
undefined, undefined]])));
|
||||
assertFalse(jspb.Message.equals(s1b,
|
||||
new proto.jspb.test.Simple1(['no', ['hello']])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
s1b, new proto.jspb.test.Simple1(['hi', ['hello']])));
|
||||
assertTrue(jspb.Message.equals(s1b, new proto.jspb.test.Simple1([
|
||||
'hi', ['hello', undefined, undefined, undefined]
|
||||
])));
|
||||
assertFalse(jspb.Message.equals(
|
||||
s1b, new proto.jspb.test.Simple1(['no', ['hello']])));
|
||||
// Test with messages of different types
|
||||
var s2 = new proto.jspb.test.Simple2(['hi']);
|
||||
assertFalse(jspb.Message.equals(s1, s2));
|
||||
@ -324,18 +328,18 @@ describe('Message test suite', function() {
|
||||
|
||||
it('testEquals_softComparison', function() {
|
||||
var s1 = new proto.jspb.test.Simple1(['hi', [], null]);
|
||||
assertTrue(jspb.Message.equals(s1,
|
||||
new proto.jspb.test.Simple1(['hi', []])));
|
||||
assertTrue(
|
||||
jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi', []])));
|
||||
|
||||
var s1b = new proto.jspb.test.Simple1(['hi', [], true]);
|
||||
assertTrue(jspb.Message.equals(s1b,
|
||||
new proto.jspb.test.Simple1(['hi', [], 1])));
|
||||
assertTrue(
|
||||
jspb.Message.equals(s1b, new proto.jspb.test.Simple1(['hi', [], 1])));
|
||||
});
|
||||
|
||||
it('testEqualsComplex', function() {
|
||||
var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
|
||||
var data2 = ['a',,, [, 11], [[, 22], [, 34]],, ['s1', 's2'],, 1];
|
||||
var data3 = ['a',,, [, 11], [[, 22]],, ['s1', 's2'],, 1];
|
||||
var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1];
|
||||
var data2 = ['a', , , [, 11], [[, 22], [, 34]], , ['s1', 's2'], , 1];
|
||||
var data3 = ['a', , , [, 11], [[, 22]], , ['s1', 's2'], , 1];
|
||||
var data4 = ['hi'];
|
||||
var c1a = new proto.jspb.test.Complex(data1);
|
||||
var c1b = new proto.jspb.test.Complex(data1);
|
||||
@ -352,42 +356,34 @@ describe('Message test suite', function() {
|
||||
it('testEqualsExtensionsConstructed', function() {
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions([]),
|
||||
new proto.jspb.test.HasExtensions([{}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions([{}])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])));
|
||||
assertFalse(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}])));
|
||||
assertTrue(jspb.Message.equals(
|
||||
new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
|
||||
));
|
||||
new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}]),
|
||||
new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])));
|
||||
});
|
||||
|
||||
it('testEqualsExtensionsUnconstructed', function() {
|
||||
assertTrue(jspb.Message.compareFields([], [{}]));
|
||||
assertTrue(jspb.Message.compareFields([,,, {}], []));
|
||||
assertTrue(jspb.Message.compareFields([,,, {}], [,, {}]));
|
||||
assertTrue(jspb.Message.compareFields([, , , {}], []));
|
||||
assertTrue(jspb.Message.compareFields([, , , {}], [, , {}]));
|
||||
assertTrue(jspb.Message.compareFields(
|
||||
['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
|
||||
assertFalse(jspb.Message.compareFields(
|
||||
@ -395,25 +391,25 @@ describe('Message test suite', function() {
|
||||
assertTrue(jspb.Message.compareFields(
|
||||
[{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
|
||||
assertTrue(jspb.Message.compareFields(
|
||||
[{100: [{200: 'a'}]}], [,,, {100: [{200: 'a'}]}]));
|
||||
[{100: [{200: 'a'}]}], [, , , {100: [{200: 'a'}]}]));
|
||||
assertTrue(jspb.Message.compareFields(
|
||||
[,,, {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
|
||||
[, , , {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
|
||||
assertTrue(jspb.Message.compareFields(
|
||||
['hi', {100: [{200: 'a'}]}], ['hi',,, {100: [{200: 'a'}]}]));
|
||||
['hi', {100: [{200: 'a'}]}], ['hi', , , {100: [{200: 'a'}]}]));
|
||||
assertTrue(jspb.Message.compareFields(
|
||||
['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
|
||||
['hi', , , {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
|
||||
});
|
||||
|
||||
it('testToMap', function() {
|
||||
var p1 = new proto.jspb.test.Simple1(['k', ['v']]);
|
||||
var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]);
|
||||
var soymap = jspb.Message.toMap([p1, p2],
|
||||
proto.jspb.test.Simple1.prototype.getAString,
|
||||
var soymap = jspb.Message.toMap(
|
||||
[p1, p2], proto.jspb.test.Simple1.prototype.getAString,
|
||||
proto.jspb.test.Simple1.prototype.toObject);
|
||||
assertEquals('k', soymap['k'].aString);
|
||||
assertArrayEquals(['v'], soymap['k'].aRepeatedStringList);
|
||||
var protomap = jspb.Message.toMap([p1, p2],
|
||||
proto.jspb.test.Simple1.prototype.getAString);
|
||||
var protomap = jspb.Message.toMap(
|
||||
[p1, p2], proto.jspb.test.Simple1.prototype.getAString);
|
||||
assertEquals('k', protomap['k'].getAString());
|
||||
assertArrayEquals(['v'], protomap['k'].getARepeatedStringList());
|
||||
});
|
||||
@ -434,8 +430,12 @@ describe('Message test suite', function() {
|
||||
extension.setExt('e1');
|
||||
original.setExtension(proto.jspb.test.IsExtension.extField, extension);
|
||||
var clone = original.clone();
|
||||
assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
|
||||
[['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
|
||||
assertArrayEquals(
|
||||
[
|
||||
'v1', , ['x1', ['y1', 'z1']], ,
|
||||
[['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, ,
|
||||
{100: [, 'e1']}
|
||||
],
|
||||
clone.toArray());
|
||||
clone.setStr('v2');
|
||||
var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]);
|
||||
@ -452,11 +452,19 @@ describe('Message test suite', function() {
|
||||
var newExtension = new proto.jspb.test.CloneExtension();
|
||||
newExtension.setExt('e2');
|
||||
clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension);
|
||||
assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],,
|
||||
[['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }],
|
||||
assertArrayEquals(
|
||||
[
|
||||
'v2', , ['a1', ['b1', 'c1']], ,
|
||||
[['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2, ,
|
||||
{100: [, 'e2']}
|
||||
],
|
||||
clone.toArray());
|
||||
assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
|
||||
[['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
|
||||
assertArrayEquals(
|
||||
[
|
||||
'v1', , ['x1', ['y1', 'z1']], ,
|
||||
[['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, ,
|
||||
{100: [, 'e1']}
|
||||
],
|
||||
original.toArray());
|
||||
});
|
||||
|
||||
@ -488,11 +496,12 @@ describe('Message test suite', function() {
|
||||
jspb.Message.copyInto(original, dest);
|
||||
assertArrayEquals(original.toArray(), dest.toArray());
|
||||
assertEquals('x1', dest.getSimple1().getAString());
|
||||
assertEquals('e1',
|
||||
assertEquals(
|
||||
'e1',
|
||||
dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt());
|
||||
dest.getSimple1().setAString('new value');
|
||||
assertNotEquals(dest.getSimple1().getAString(),
|
||||
original.getSimple1().getAString());
|
||||
assertNotEquals(
|
||||
dest.getSimple1().getAString(), original.getSimple1().getAString());
|
||||
if (supportsUint8Array) {
|
||||
dest.getBytesField()[0] = 7;
|
||||
assertObjectEquals(bytes1, original.getBytesField());
|
||||
@ -502,12 +511,12 @@ describe('Message test suite', function() {
|
||||
assertObjectEquals(bytes1, original.getBytesField());
|
||||
assertObjectEquals('789', dest.getBytesField());
|
||||
}
|
||||
dest.getExtension(proto.jspb.test.CloneExtension.extField).
|
||||
setExt('new value');
|
||||
dest.getExtension(proto.jspb.test.CloneExtension.extField)
|
||||
.setExt('new value');
|
||||
assertNotEquals(
|
||||
dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(),
|
||||
original.getExtension(
|
||||
proto.jspb.test.CloneExtension.extField).getExt());
|
||||
original.getExtension(proto.jspb.test.CloneExtension.extField)
|
||||
.getExt());
|
||||
});
|
||||
|
||||
it('testCopyInto_notSameType', function() {
|
||||
@ -525,26 +534,32 @@ describe('Message test suite', function() {
|
||||
var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]);
|
||||
var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
|
||||
extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
|
||||
extension2);
|
||||
extendable.setExtension(
|
||||
proto.jspb.test.IndirectExtension.simple, extension2);
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
|
||||
['a', 'b']);
|
||||
extendable.setExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']);
|
||||
var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
|
||||
var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]);
|
||||
extendable.setExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedSimpleList,
|
||||
[s1, s2]);
|
||||
assertObjectEquals(extension1,
|
||||
proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]);
|
||||
assertObjectEquals(
|
||||
extension1,
|
||||
extendable.getExtension(proto.jspb.test.IsExtension.extField));
|
||||
assertObjectEquals(extension2,
|
||||
assertObjectEquals(
|
||||
extension2,
|
||||
extendable.getExtension(proto.jspb.test.IndirectExtension.simple));
|
||||
assertObjectEquals('xyzzy',
|
||||
assertObjectEquals(
|
||||
'xyzzy',
|
||||
extendable.getExtension(proto.jspb.test.IndirectExtension.str));
|
||||
assertObjectEquals(['a', 'b'], extendable.getExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedStrList));
|
||||
assertObjectEquals([s1, s2], extendable.getExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedSimpleList));
|
||||
assertObjectEquals(
|
||||
['a', 'b'],
|
||||
extendable.getExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedStrList));
|
||||
assertObjectEquals(
|
||||
[s1, s2],
|
||||
extendable.getExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedSimpleList));
|
||||
// Not supported yet, but it should work...
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null);
|
||||
assertNull(
|
||||
@ -563,18 +578,18 @@ describe('Message test suite', function() {
|
||||
var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
|
||||
var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
|
||||
extendable.setExtension(proto.jspb.test.simple1, extension);
|
||||
assertObjectEquals(extension,
|
||||
extendable.getExtension(proto.jspb.test.simple1));
|
||||
assertObjectEquals(
|
||||
extension, extendable.getExtension(proto.jspb.test.simple1));
|
||||
|
||||
// From _lib mode.
|
||||
extension = new proto.jspb.test.ExtensionMessage(['s1']);
|
||||
extendable = new proto.jspb.test.TestExtensionsMessage([16]);
|
||||
extendable.setExtension(proto.jspb.test.floatingMsgField, extension);
|
||||
extendable.setExtension(proto.jspb.test.floatingStrField, 's2');
|
||||
assertObjectEquals(extension,
|
||||
extendable.getExtension(proto.jspb.test.floatingMsgField));
|
||||
assertObjectEquals('s2',
|
||||
extendable.getExtension(proto.jspb.test.floatingStrField));
|
||||
assertObjectEquals(
|
||||
extension, extendable.getExtension(proto.jspb.test.floatingMsgField));
|
||||
assertObjectEquals(
|
||||
's2', extendable.getExtension(proto.jspb.test.floatingStrField));
|
||||
assertNotUndefined(proto.jspb.exttest.floatingMsgField);
|
||||
assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo);
|
||||
assertNotUndefined(proto.jspb.exttest.beta.floatingStrField);
|
||||
@ -585,60 +600,72 @@ describe('Message test suite', function() {
|
||||
var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]);
|
||||
var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
|
||||
extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
|
||||
extension2);
|
||||
extendable.setExtension(
|
||||
proto.jspb.test.IndirectExtension.simple, extension2);
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
|
||||
extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
|
||||
['a', 'b']);
|
||||
extendable.setExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']);
|
||||
var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]);
|
||||
var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]);
|
||||
extendable.setExtension(
|
||||
proto.jspb.test.IndirectExtension.repeatedSimpleList,
|
||||
[s1, s2]);
|
||||
assertObjectEquals({
|
||||
str1: 'v1', str2: 'v2', str3: 'v3',
|
||||
extField: { ext1: 'ext1field' },
|
||||
simple: {
|
||||
aString: 'str', aRepeatedStringList: ['s1', 's2'], aBoolean: true
|
||||
},
|
||||
str: 'xyzzy',
|
||||
repeatedStrList: ['a', 'b'],
|
||||
repeatedSimpleList: [
|
||||
{ aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true},
|
||||
{ aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false}
|
||||
]
|
||||
}, extendable.toObject());
|
||||
proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]);
|
||||
assertObjectEquals(
|
||||
{
|
||||
str1: 'v1',
|
||||
str2: 'v2',
|
||||
str3: 'v3',
|
||||
extField: {ext1: 'ext1field'},
|
||||
simple: {
|
||||
aString: 'str',
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
aBoolean: true
|
||||
},
|
||||
str: 'xyzzy',
|
||||
repeatedStrList: ['a', 'b'],
|
||||
repeatedSimpleList: [
|
||||
{aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true},
|
||||
{aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false}
|
||||
]
|
||||
},
|
||||
extendable.toObject());
|
||||
|
||||
// Now, with instances included.
|
||||
assertObjectEquals({
|
||||
str1: 'v1', str2: 'v2', str3: 'v3',
|
||||
extField: {
|
||||
ext1: 'ext1field',
|
||||
$jspbMessageInstance:
|
||||
extendable.getExtension(proto.jspb.test.IsExtension.extField)
|
||||
},
|
||||
simple: {
|
||||
aString: 'str',
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
aBoolean: true,
|
||||
$jspbMessageInstance:
|
||||
extendable.getExtension(proto.jspb.test.IndirectExtension.simple)
|
||||
},
|
||||
str: 'xyzzy',
|
||||
repeatedStrList: ['a', 'b'],
|
||||
repeatedSimpleList: [{
|
||||
aString: 'foo',
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
aBoolean: true,
|
||||
$jspbMessageInstance: s1
|
||||
}, {
|
||||
aString: 'bar',
|
||||
aRepeatedStringList: ['t1', 't2'],
|
||||
aBoolean: false,
|
||||
$jspbMessageInstance: s2
|
||||
}],
|
||||
$jspbMessageInstance: extendable
|
||||
}, extendable.toObject(true /* opt_includeInstance */));
|
||||
assertObjectEquals(
|
||||
{
|
||||
str1: 'v1',
|
||||
str2: 'v2',
|
||||
str3: 'v3',
|
||||
extField: {
|
||||
ext1: 'ext1field',
|
||||
$jspbMessageInstance:
|
||||
extendable.getExtension(proto.jspb.test.IsExtension.extField)
|
||||
},
|
||||
simple: {
|
||||
aString: 'str',
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
aBoolean: true,
|
||||
$jspbMessageInstance: extendable.getExtension(
|
||||
proto.jspb.test.IndirectExtension.simple)
|
||||
},
|
||||
str: 'xyzzy',
|
||||
repeatedStrList: ['a', 'b'],
|
||||
repeatedSimpleList: [
|
||||
{
|
||||
aString: 'foo',
|
||||
aRepeatedStringList: ['s1', 's2'],
|
||||
aBoolean: true,
|
||||
$jspbMessageInstance: s1
|
||||
},
|
||||
{
|
||||
aString: 'bar',
|
||||
aRepeatedStringList: ['t1', 't2'],
|
||||
aBoolean: false,
|
||||
$jspbMessageInstance: s2
|
||||
}
|
||||
],
|
||||
$jspbMessageInstance: extendable
|
||||
},
|
||||
extendable.toObject(true /* opt_includeInstance */));
|
||||
});
|
||||
|
||||
it('testInitialization_emptyArray', function() {
|
||||
@ -690,8 +717,7 @@ describe('Message test suite', function() {
|
||||
var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']);
|
||||
data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage);
|
||||
var obj = data.toObject();
|
||||
assertNotNull(
|
||||
data.getExtension(proto.jspb.test.IsExtension.extField));
|
||||
assertNotNull(data.getExtension(proto.jspb.test.IsExtension.extField));
|
||||
assertEquals('is_extension', obj.extField.ext1);
|
||||
});
|
||||
|
||||
@ -708,16 +734,18 @@ describe('Message test suite', function() {
|
||||
var groups = group.getRepeatedGroupList();
|
||||
assertEquals('g1', groups[0].getId());
|
||||
assertObjectEquals([true, false], groups[0].getSomeBoolList());
|
||||
assertObjectEquals({id: 'g1', someBoolList: [true, false]},
|
||||
groups[0].toObject());
|
||||
assertObjectEquals({
|
||||
repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}],
|
||||
requiredGroup: {id: undefined},
|
||||
optionalGroup: undefined,
|
||||
requiredSimple: {aRepeatedStringList: [], aString: undefined},
|
||||
optionalSimple: undefined,
|
||||
id: undefined
|
||||
}, group.toObject());
|
||||
assertObjectEquals(
|
||||
{id: 'g1', someBoolList: [true, false]}, groups[0].toObject());
|
||||
assertObjectEquals(
|
||||
{
|
||||
repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}],
|
||||
requiredGroup: {id: undefined},
|
||||
optionalGroup: undefined,
|
||||
requiredSimple: {aRepeatedStringList: [], aString: undefined},
|
||||
optionalSimple: undefined,
|
||||
id: undefined
|
||||
},
|
||||
group.toObject());
|
||||
var group1 = new proto.jspb.test.TestGroup1();
|
||||
group1.setGroup(someGroup);
|
||||
assertEquals(someGroup, group1.getGroup());
|
||||
@ -734,25 +762,26 @@ describe('Message test suite', function() {
|
||||
message.setExtension$(11);
|
||||
message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12);
|
||||
assertEquals(11, message.getExtension$());
|
||||
assertEquals(12, message.getExtension(
|
||||
proto.jspb.test.TestReservedNamesExtension.foo));
|
||||
assertEquals(
|
||||
12,
|
||||
message.getExtension(proto.jspb.test.TestReservedNamesExtension.foo));
|
||||
assertObjectEquals({extension: 11, foo: 12}, message.toObject());
|
||||
});
|
||||
|
||||
it('testInitializeMessageWithUnsetOneof', function() {
|
||||
var message = new proto.jspb.test.TestMessageWithOneof([]);
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
|
||||
PARTIAL_ONEOF_NOT_SET,
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase
|
||||
.PARTIAL_ONEOF_NOT_SET,
|
||||
message.getPartialOneofCase());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
|
||||
RECURSIVE_ONEOF_NOT_SET,
|
||||
proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase
|
||||
.RECURSIVE_ONEOF_NOT_SET,
|
||||
message.getRecursiveOneofCase());
|
||||
});
|
||||
|
||||
it('testInitializeMessageWithSingleValueSetInOneof', function() {
|
||||
var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']);
|
||||
var message = new proto.jspb.test.TestMessageWithOneof([, , 'x']);
|
||||
|
||||
assertEquals('x', message.getPone());
|
||||
assertEquals('', message.getPthree());
|
||||
@ -762,7 +791,7 @@ describe('Message test suite', function() {
|
||||
});
|
||||
|
||||
it('testKeepsLastWireValueSetInUnion_multipleValues', function() {
|
||||
var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']);
|
||||
var message = new proto.jspb.test.TestMessageWithOneof([, , 'x', , 'y']);
|
||||
|
||||
assertEquals('', message.getPone());
|
||||
assertEquals('y', message.getPthree());
|
||||
@ -819,8 +848,8 @@ describe('Message test suite', function() {
|
||||
it('testUnsetsOneofCaseWhenFieldIsCleared', function() {
|
||||
var message = new proto.jspb.test.TestMessageWithOneof;
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
|
||||
PARTIAL_ONEOF_NOT_SET,
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase
|
||||
.PARTIAL_ONEOF_NOT_SET,
|
||||
message.getPartialOneofCase());
|
||||
|
||||
message.setPone('hi');
|
||||
@ -830,8 +859,8 @@ describe('Message test suite', function() {
|
||||
|
||||
message.clearPone();
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
|
||||
PARTIAL_ONEOF_NOT_SET,
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase
|
||||
.PARTIAL_ONEOF_NOT_SET,
|
||||
message.getPartialOneofCase());
|
||||
});
|
||||
|
||||
@ -934,39 +963,39 @@ describe('Message test suite', function() {
|
||||
});
|
||||
|
||||
it('testInitializeMessageWithOneofDefaults_defaultNotSetOnFirstField',
|
||||
function() {
|
||||
var message;
|
||||
function() {
|
||||
var message;
|
||||
|
||||
message =
|
||||
new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567));
|
||||
assertEquals(567, message.getBone());
|
||||
assertEquals(1234, message.getBtwo());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
|
||||
message.getDefaultOneofBCase());
|
||||
message =
|
||||
new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567));
|
||||
assertEquals(567, message.getBone());
|
||||
assertEquals(1234, message.getBtwo());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
|
||||
message.getDefaultOneofBCase());
|
||||
|
||||
message =
|
||||
new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
|
||||
assertEquals(0, message.getBone());
|
||||
assertEquals(890, message.getBtwo());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
||||
message.getDefaultOneofBCase());
|
||||
message =
|
||||
new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
|
||||
assertEquals(0, message.getBone());
|
||||
assertEquals(890, message.getBtwo());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
||||
message.getDefaultOneofBCase());
|
||||
|
||||
message = new proto.jspb.test.TestMessageWithOneof(
|
||||
new Array(11).concat(567, 890));
|
||||
assertEquals(0, message.getBone());
|
||||
assertEquals(890, message.getBtwo());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
||||
message.getDefaultOneofBCase());
|
||||
});
|
||||
message = new proto.jspb.test.TestMessageWithOneof(
|
||||
new Array(11).concat(567, 890));
|
||||
assertEquals(0, message.getBone());
|
||||
assertEquals(890, message.getBtwo());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
|
||||
message.getDefaultOneofBCase());
|
||||
});
|
||||
|
||||
it('testOneofContainingAnotherMessage', function() {
|
||||
var message = new proto.jspb.test.TestMessageWithOneof;
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
|
||||
RECURSIVE_ONEOF_NOT_SET,
|
||||
proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase
|
||||
.RECURSIVE_ONEOF_NOT_SET,
|
||||
message.getRecursiveOneofCase());
|
||||
|
||||
var other = new proto.jspb.test.TestMessageWithOneof;
|
||||
@ -987,25 +1016,25 @@ describe('Message test suite', function() {
|
||||
|
||||
it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray',
|
||||
function() {
|
||||
var message = new proto.jspb.test.TestMessageWithOneof;
|
||||
message.setPone('x');
|
||||
assertEquals('x', message.getPone());
|
||||
assertEquals('', message.getPthree());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
|
||||
message.getPartialOneofCase());
|
||||
var message = new proto.jspb.test.TestMessageWithOneof;
|
||||
message.setPone('x');
|
||||
assertEquals('x', message.getPone());
|
||||
assertEquals('', message.getPthree());
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
|
||||
message.getPartialOneofCase());
|
||||
|
||||
var array = message.toArray();
|
||||
assertEquals('x', array[2]);
|
||||
assertUndefined(array[4]);
|
||||
array[4] = 'y';
|
||||
var array = message.toArray();
|
||||
assertEquals('x', array[2]);
|
||||
assertUndefined(array[4]);
|
||||
array[4] = 'y';
|
||||
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
|
||||
message.getPartialOneofCase());
|
||||
assertUndefined(array[2]);
|
||||
assertEquals('y', array[4]);
|
||||
});
|
||||
assertEquals(
|
||||
proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
|
||||
message.getPartialOneofCase());
|
||||
assertUndefined(array[2]);
|
||||
assertEquals('y', array[4]);
|
||||
});
|
||||
|
||||
it('testFloatingPointFieldsSupportNan', function() {
|
||||
var assertNan = function(x) {
|
||||
@ -1015,8 +1044,7 @@ describe('Message test suite', function() {
|
||||
};
|
||||
|
||||
var message = new proto.jspb.test.FloatingPointFields([
|
||||
'NaN', 'NaN', ['NaN', 'NaN'], 'NaN',
|
||||
'NaN', 'NaN', ['NaN', 'NaN'], 'NaN'
|
||||
'NaN', 'NaN', ['NaN', 'NaN'], 'NaN', 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN'
|
||||
]);
|
||||
assertNan(message.getOptionalFloatField());
|
||||
assertNan(message.getRequiredFloatField());
|
||||
@ -1029,5 +1057,4 @@ describe('Message test suite', function() {
|
||||
assertNan(message.getRepeatedDoubleFieldList()[1]);
|
||||
assertNan(message.getDefaultDoubleField());
|
||||
});
|
||||
|
||||
});
|
||||
|
161
js/maps_test.js
161
js/maps_test.js
@ -53,6 +53,8 @@ goog.require('proto.jspb.test.MapEntryOptionalValuesMessageValue');
|
||||
goog.require('proto.jspb.test.MapValueMessageNoBinary');
|
||||
goog.require('proto.jspb.test.TestMapFieldsNoBinary');
|
||||
|
||||
goog.requireType('jspb.Map');
|
||||
|
||||
/**
|
||||
* Helper: check that the given map has exactly this set of (sorted) entries.
|
||||
* @param {!jspb.Map} map
|
||||
@ -116,7 +118,9 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
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.getMapInt64StringMap()
|
||||
.set(0x123456789abc, 'c')
|
||||
.set(0xcba987654321, 'd');
|
||||
msg.getMapBoolStringMap().set(false, 'e').set(true, 'f');
|
||||
};
|
||||
|
||||
@ -125,42 +129,24 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
* @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.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']
|
||||
['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);
|
||||
@ -205,10 +191,7 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
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']
|
||||
]);
|
||||
checkMapEquals(m, [['asdf', 'hello world'], ['jkl;', 'key 2']]);
|
||||
m.del('jkl;');
|
||||
assertEquals(m.has('jkl;'), false);
|
||||
assertEquals(m.get('jkl;'), undefined);
|
||||
@ -260,11 +243,11 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
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'
|
||||
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++) {
|
||||
@ -284,34 +267,27 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
* binary format.
|
||||
*/
|
||||
it('testMapDeserializationForUndefinedKeys', function() {
|
||||
var testMessageOptionalKeys = new proto.jspb.test.TestMapFieldsOptionalKeys();
|
||||
var mapEntryStringKey = new proto.jspb.test.MapEntryOptionalKeysStringKey();
|
||||
mapEntryStringKey.setValue("a");
|
||||
var testMessageOptionalKeys =
|
||||
new proto.jspb.test.TestMapFieldsOptionalKeys();
|
||||
var mapEntryStringKey =
|
||||
new proto.jspb.test.MapEntryOptionalKeysStringKey();
|
||||
mapEntryStringKey.setValue('a');
|
||||
testMessageOptionalKeys.setMapStringString(mapEntryStringKey);
|
||||
var mapEntryInt32Key = new proto.jspb.test.MapEntryOptionalKeysInt32Key();
|
||||
mapEntryInt32Key.setValue("b");
|
||||
mapEntryInt32Key.setValue('b');
|
||||
testMessageOptionalKeys.setMapInt32String(mapEntryInt32Key);
|
||||
var mapEntryInt64Key = new proto.jspb.test.MapEntryOptionalKeysInt64Key();
|
||||
mapEntryInt64Key.setValue("c");
|
||||
mapEntryInt64Key.setValue('c');
|
||||
testMessageOptionalKeys.setMapInt64String(mapEntryInt64Key);
|
||||
var mapEntryBoolKey = new proto.jspb.test.MapEntryOptionalKeysBoolKey();
|
||||
mapEntryBoolKey.setValue("d");
|
||||
mapEntryBoolKey.setValue('d');
|
||||
testMessageOptionalKeys.setMapBoolString(mapEntryBoolKey);
|
||||
var deserializedMessage = msgInfo.deserializeBinary(
|
||||
testMessageOptionalKeys.serializeBinary()
|
||||
);
|
||||
checkMapEquals(deserializedMessage.getMapStringStringMap(), [
|
||||
['', 'a']
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapInt32StringMap(), [
|
||||
[0, 'b']
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapInt64StringMap(), [
|
||||
[0, 'c']
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapBoolStringMap(), [
|
||||
[false, 'd']
|
||||
]);
|
||||
var deserializedMessage =
|
||||
msgInfo.deserializeBinary(testMessageOptionalKeys.serializeBinary());
|
||||
checkMapEquals(deserializedMessage.getMapStringStringMap(), [['', 'a']]);
|
||||
checkMapEquals(deserializedMessage.getMapInt32StringMap(), [[0, 'b']]);
|
||||
checkMapEquals(deserializedMessage.getMapInt64StringMap(), [[0, 'c']]);
|
||||
checkMapEquals(deserializedMessage.getMapBoolStringMap(), [[false, 'd']]);
|
||||
});
|
||||
|
||||
/**
|
||||
@ -323,56 +299,41 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
new proto.jspb.test.TestMapFieldsOptionalValues();
|
||||
var mapEntryStringValue =
|
||||
new proto.jspb.test.MapEntryOptionalValuesStringValue();
|
||||
mapEntryStringValue.setKey("a");
|
||||
mapEntryStringValue.setKey('a');
|
||||
testMessageOptionalValues.setMapStringString(mapEntryStringValue);
|
||||
var mapEntryInt32Value =
|
||||
new proto.jspb.test.MapEntryOptionalValuesInt32Value();
|
||||
mapEntryInt32Value.setKey("b");
|
||||
mapEntryInt32Value.setKey('b');
|
||||
testMessageOptionalValues.setMapStringInt32(mapEntryInt32Value);
|
||||
var mapEntryInt64Value =
|
||||
new proto.jspb.test.MapEntryOptionalValuesInt64Value();
|
||||
mapEntryInt64Value.setKey("c");
|
||||
mapEntryInt64Value.setKey('c');
|
||||
testMessageOptionalValues.setMapStringInt64(mapEntryInt64Value);
|
||||
var mapEntryBoolValue =
|
||||
new proto.jspb.test.MapEntryOptionalValuesBoolValue();
|
||||
mapEntryBoolValue.setKey("d");
|
||||
mapEntryBoolValue.setKey('d');
|
||||
testMessageOptionalValues.setMapStringBool(mapEntryBoolValue);
|
||||
var mapEntryDoubleValue =
|
||||
new proto.jspb.test.MapEntryOptionalValuesDoubleValue();
|
||||
mapEntryDoubleValue.setKey("e");
|
||||
mapEntryDoubleValue.setKey('e');
|
||||
testMessageOptionalValues.setMapStringDouble(mapEntryDoubleValue);
|
||||
var mapEntryEnumValue =
|
||||
new proto.jspb.test.MapEntryOptionalValuesEnumValue();
|
||||
mapEntryEnumValue.setKey("f");
|
||||
mapEntryEnumValue.setKey('f');
|
||||
testMessageOptionalValues.setMapStringEnum(mapEntryEnumValue);
|
||||
var mapEntryMessageValue =
|
||||
new proto.jspb.test.MapEntryOptionalValuesMessageValue();
|
||||
mapEntryMessageValue.setKey("g");
|
||||
mapEntryMessageValue.setKey('g');
|
||||
testMessageOptionalValues.setMapStringMsg(mapEntryMessageValue);
|
||||
var deserializedMessage = msgInfo.deserializeBinary(
|
||||
testMessageOptionalValues.serializeBinary()
|
||||
);
|
||||
checkMapEquals(deserializedMessage.getMapStringStringMap(), [
|
||||
['a', '']
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapStringInt32Map(), [
|
||||
['b', 0]
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapStringInt64Map(), [
|
||||
['c', 0]
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapStringBoolMap(), [
|
||||
['d', false]
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapStringDoubleMap(), [
|
||||
['e', 0.0]
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapStringEnumMap(), [
|
||||
['f', 0]
|
||||
]);
|
||||
checkMapEquals(deserializedMessage.getMapStringMsgMap(), [
|
||||
['g', []]
|
||||
]);
|
||||
testMessageOptionalValues.serializeBinary());
|
||||
checkMapEquals(deserializedMessage.getMapStringStringMap(), [['a', '']]);
|
||||
checkMapEquals(deserializedMessage.getMapStringInt32Map(), [['b', 0]]);
|
||||
checkMapEquals(deserializedMessage.getMapStringInt64Map(), [['c', 0]]);
|
||||
checkMapEquals(deserializedMessage.getMapStringBoolMap(), [['d', false]]);
|
||||
checkMapEquals(deserializedMessage.getMapStringDoubleMap(), [['e', 0.0]]);
|
||||
checkMapEquals(deserializedMessage.getMapStringEnumMap(), [['f', 0]]);
|
||||
checkMapEquals(deserializedMessage.getMapStringMsgMap(), [['g', []]]);
|
||||
});
|
||||
}
|
||||
|
||||
@ -382,11 +343,7 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
*/
|
||||
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 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');
|
||||
@ -394,9 +351,9 @@ function makeTests(msgInfo, submessageCtor, suffix) {
|
||||
assertEquals(entries[2][0], 'b');
|
||||
msg.getMapStringStringMap().del('a');
|
||||
assertEquals(entries.length, 3); // not yet sync'd
|
||||
msg.toArray(); // force a sync
|
||||
msg.toArray(); // force a sync
|
||||
assertEquals(entries.length, 2);
|
||||
assertEquals(entries[0][0], 'b'); // now in sorted order
|
||||
assertEquals(entries[0][0], 'b'); // now in sorted order
|
||||
assertEquals(entries[1][0], 'c');
|
||||
|
||||
var a = msg.toArray();
|
||||
|
@ -121,6 +121,8 @@ goog.require('proto.jspb.test.TestAllowAliasEnum');
|
||||
// CommonJS-LoadFromFile: testlargenumbers_pb proto.jspb.test
|
||||
goog.require('proto.jspb.test.MessageWithLargeFieldNumbers');
|
||||
|
||||
goog.require('proto.jspb.test.simple1');
|
||||
|
||||
describe('Message test suite', function() {
|
||||
var stubs = new goog.testing.PropertyReplacer();
|
||||
|
||||
@ -185,7 +187,6 @@ describe('Message test suite', function() {
|
||||
$jspbMessageInstance: foo
|
||||
},
|
||||
result);
|
||||
|
||||
});
|
||||
|
||||
it('testMissingFields', function() {
|
||||
@ -209,7 +210,6 @@ describe('Message test suite', function() {
|
||||
aFloatingPointField: undefined,
|
||||
},
|
||||
result);
|
||||
|
||||
});
|
||||
|
||||
it('testNestedComplexMessage', function() {
|
||||
@ -1108,5 +1108,4 @@ describe('Message test suite', function() {
|
||||
message.setAInt(42);
|
||||
assertEquals(42, message.getAInt());
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -41,7 +41,7 @@ goog.require('proto.google.protobuf.Any');
|
||||
goog.require('proto.google.protobuf.Timestamp');
|
||||
// CommonJS-LoadFromFile: google/protobuf/struct_pb proto.google.protobuf
|
||||
goog.require('proto.google.protobuf.Struct');
|
||||
|
||||
goog.require('jspb.Message');
|
||||
|
||||
var BYTES = new Uint8Array([1, 2, 8, 9]);
|
||||
var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES);
|
||||
@ -70,7 +70,6 @@ function bytesCompare(arr, expected) {
|
||||
|
||||
|
||||
describe('proto3Test', function() {
|
||||
|
||||
/**
|
||||
* Test default values don't affect equality test.
|
||||
*/
|
||||
@ -182,8 +181,8 @@ describe('proto3Test', function() {
|
||||
assertEquals(msg.getOptionalBytes_asU8().length, 0);
|
||||
assertEquals(msg.getOptionalBytes_asB64(), '');
|
||||
|
||||
assertEquals(msg.getOptionalForeignEnum(),
|
||||
proto.jspb.test.Proto3Enum.PROTO3_FOO);
|
||||
assertEquals(
|
||||
msg.getOptionalForeignEnum(), proto.jspb.test.Proto3Enum.PROTO3_FOO);
|
||||
assertEquals(msg.getOptionalForeignMessage(), undefined);
|
||||
assertEquals(msg.getOptionalForeignMessage(), undefined);
|
||||
|
||||
@ -309,7 +308,8 @@ describe('proto3Test', function() {
|
||||
assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], BYTES));
|
||||
assertEquals(msg.getRepeatedForeignMessageList().length, 1);
|
||||
assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000);
|
||||
assertElementsEquals(msg.getRepeatedForeignEnumList(),
|
||||
assertElementsEquals(
|
||||
msg.getRepeatedForeignEnumList(),
|
||||
[proto.jspb.test.Proto3Enum.PROTO3_BAR]);
|
||||
|
||||
assertEquals(msg.getOneofString(), 'asdf');
|
||||
@ -374,7 +374,8 @@ describe('proto3Test', function() {
|
||||
assertEquals(msg.getOneofUint32(), 0);
|
||||
assertEquals(msg.getOneofForeignMessage(), undefined);
|
||||
assertEquals(msg.getOneofString(), '');
|
||||
assertEquals(msg.getOneofBytes_asB64(),
|
||||
assertEquals(
|
||||
msg.getOneofBytes_asB64(),
|
||||
goog.crypt.base64.encodeString('\u00FF\u00FF'));
|
||||
|
||||
assertFalse(msg.hasOneofUint32());
|
||||
@ -454,24 +455,24 @@ describe('proto3Test', function() {
|
||||
|
||||
it('testStructWellKnownType', function() {
|
||||
var jsObj = {
|
||||
abc: "def",
|
||||
abc: 'def',
|
||||
number: 12345.678,
|
||||
nullKey: null,
|
||||
boolKey: true,
|
||||
listKey: [1, null, true, false, "abc"],
|
||||
structKey: {foo: "bar", somenum: 123},
|
||||
complicatedKey: [{xyz: {abc: [3, 4, null, false]}}, "zzz"]
|
||||
listKey: [1, null, true, false, 'abc'],
|
||||
structKey: {foo: 'bar', somenum: 123},
|
||||
complicatedKey: [{xyz: {abc: [3, 4, null, false]}}, 'zzz']
|
||||
};
|
||||
|
||||
var struct = proto.google.protobuf.Struct.fromJavaScript(jsObj);
|
||||
var jsObj2 = struct.toJavaScript();
|
||||
|
||||
assertEquals("def", jsObj2.abc);
|
||||
assertEquals('def', jsObj2.abc);
|
||||
assertEquals(12345.678, jsObj2.number);
|
||||
assertEquals(null, jsObj2.nullKey);
|
||||
assertEquals(true, jsObj2.boolKey);
|
||||
assertEquals("abc", jsObj2.listKey[4]);
|
||||
assertEquals("bar", jsObj2.structKey.foo);
|
||||
assertEquals('abc', jsObj2.listKey[4]);
|
||||
assertEquals('bar', jsObj2.structKey.foo);
|
||||
assertEquals(4, jsObj2.complicatedKey[0].xyz.abc[1]);
|
||||
});
|
||||
});
|
||||
|
@ -49,6 +49,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
|
||||
* This option does nothing.
|
||||
*
|
||||
* Generated from protobuf field <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code>
|
||||
* @deprecated
|
||||
*/
|
||||
protected $java_generate_equals_and_hash = null;
|
||||
/**
|
||||
@ -412,19 +413,23 @@ class FileOptions extends \Google\Protobuf\Internal\Message
|
||||
*
|
||||
* Generated from protobuf field <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code>
|
||||
* @return bool
|
||||
* @deprecated
|
||||
*/
|
||||
public function getJavaGenerateEqualsAndHash()
|
||||
{
|
||||
@trigger_error('java_generate_equals_and_hash is deprecated.', E_USER_DEPRECATED);
|
||||
return isset($this->java_generate_equals_and_hash) ? $this->java_generate_equals_and_hash : false;
|
||||
}
|
||||
|
||||
public function hasJavaGenerateEqualsAndHash()
|
||||
{
|
||||
@trigger_error('java_generate_equals_and_hash is deprecated.', E_USER_DEPRECATED);
|
||||
return isset($this->java_generate_equals_and_hash);
|
||||
}
|
||||
|
||||
public function clearJavaGenerateEqualsAndHash()
|
||||
{
|
||||
@trigger_error('java_generate_equals_and_hash is deprecated.', E_USER_DEPRECATED);
|
||||
unset($this->java_generate_equals_and_hash);
|
||||
}
|
||||
|
||||
@ -434,9 +439,11 @@ class FileOptions extends \Google\Protobuf\Internal\Message
|
||||
* Generated from protobuf field <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code>
|
||||
* @param bool $var
|
||||
* @return $this
|
||||
* @deprecated
|
||||
*/
|
||||
public function setJavaGenerateEqualsAndHash($var)
|
||||
{
|
||||
@trigger_error('java_generate_equals_and_hash is deprecated.', E_USER_DEPRECATED);
|
||||
GPBUtil::checkBool($var);
|
||||
$this->java_generate_equals_and_hash = $var;
|
||||
|
||||
|
@ -327,7 +327,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
template <typename T>
|
||||
PROTOBUF_NDEBUG_INLINE static T* CreateArray(Arena* arena,
|
||||
size_t num_elements) {
|
||||
static_assert(std::is_standard_layout<T>::value && std::is_trivial<T>::value,
|
||||
static_assert(std::is_trivially_default_constructible<T>::value,
|
||||
"CreateArray requires a trivially constructible type");
|
||||
static_assert(std::is_trivially_destructible<T>::value,
|
||||
"CreateArray requires a trivially destructible type");
|
||||
|
@ -1216,21 +1216,9 @@ PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name) {
|
||||
|
||||
bool CommandLineInterface::AllowProto3Optional(
|
||||
const FileDescriptor& file) const {
|
||||
// If the --experimental_allow_proto3_optional flag was set, we allow.
|
||||
if (allow_proto3_optional_) return true;
|
||||
|
||||
// Whitelist all ads protos. Ads is an early adopter of this feature.
|
||||
if (file.name().find("google/ads/googleads") != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Whitelist all protos testing proto3 optional.
|
||||
if (file.name().find("test_proto3_optional") != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
// Proto3 optional is enabled by default now, the experimental flag is no
|
||||
// longer required.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2378,48 +2378,6 @@ TEST_F(CommandLineInterfaceTest, MissingValueAtEndError) {
|
||||
ExpectErrorText("Missing value for flag: --test_out\n");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowed) {
|
||||
CreateTempFile("google/foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --proto_path=$tmpdir google/foo.proto "
|
||||
"-odescriptor.pb");
|
||||
|
||||
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedDescriptor) {
|
||||
CreateTempFile("google/foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --experimental_allow_proto3_optional "
|
||||
"--proto_path=$tmpdir google/foo.proto "
|
||||
" -o$tmpdir/descriptor.pb");
|
||||
ExpectNoErrors();
|
||||
|
||||
Run("protocol_compiler --descriptor_set_in=$tmpdir/descriptor.pb"
|
||||
" google/foo.proto --test_out=$tmpdir");
|
||||
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedGenCode) {
|
||||
CreateTempFile("google/foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --proto_path=$tmpdir google/foo.proto "
|
||||
"--test_out=$tmpdir");
|
||||
|
||||
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedNoCodegenSupport) {
|
||||
CreateTempFile("google/foo.proto",
|
||||
|
@ -75,11 +75,6 @@ std::string GetSortKey<FileDescriptor>(const FileDescriptor& val) {
|
||||
return val.name();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string GetSortKey<SCC>(const SCC& val) {
|
||||
return val.GetRepresentative()->full_name();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool CompareSortKeys(const T* a, const T* b) {
|
||||
return GetSortKey(*a) < GetSortKey(*b);
|
||||
|
@ -49,6 +49,7 @@ namespace protobuf {
|
||||
namespace compiler {
|
||||
namespace java {
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
|
||||
|
@ -28,9 +28,19 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <google/protobuf/compiler/js/js_generator.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <google/protobuf/compiler/js/js_generator.h>
|
||||
#include <google/protobuf/compiler/js/well_known_types_embed.h>
|
||||
#include <google/protobuf/compiler/scc.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <google/protobuf/io/printer.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/stubs/stringprintf.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
@ -39,17 +49,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/stringprintf.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
#include <google/protobuf/compiler/scc.h>
|
||||
#include <google/protobuf/compiler/js/well_known_types_embed.h>
|
||||
#include <google/protobuf/io/printer.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace compiler {
|
||||
@ -173,8 +172,8 @@ std::string GetNestedMessageName(const Descriptor* descriptor) {
|
||||
if (descriptor == NULL) {
|
||||
return "";
|
||||
}
|
||||
std::string result = StripPrefixString(
|
||||
descriptor->full_name(), descriptor->file()->package());
|
||||
std::string result =
|
||||
StripPrefixString(descriptor->full_name(), descriptor->file()->package());
|
||||
// Add a leading dot if one is not already present.
|
||||
if (!result.empty() && result[0] != '.') {
|
||||
result = "." + result;
|
||||
@ -411,7 +410,7 @@ std::string GetMessagesFileName(const GeneratorOptions& options, const SCC* scc,
|
||||
GetSnakeFilename(scc->GetRepresentative()->file()->name()));
|
||||
(*long_name_dict)[scc->GetRepresentative()] =
|
||||
StrCat(snake_name, "_long_sccs_",
|
||||
static_cast<uint64>((*long_name_dict).size()));
|
||||
static_cast<uint64>((*long_name_dict).size()));
|
||||
}
|
||||
filename_base = (*long_name_dict)[scc->GetRepresentative()];
|
||||
}
|
||||
@ -431,9 +430,7 @@ std::string GetEnumFileName(const GeneratorOptions& options,
|
||||
}
|
||||
|
||||
// Returns the message/response ID, if set.
|
||||
std::string GetMessageId(const Descriptor* desc) {
|
||||
return std::string();
|
||||
}
|
||||
std::string GetMessageId(const Descriptor* desc) { return std::string(); }
|
||||
|
||||
bool IgnoreExtensionField(const FieldDescriptor* field) {
|
||||
// Exclude descriptor extensions from output "to avoid clutter" (from original
|
||||
@ -444,7 +441,6 @@ bool IgnoreExtensionField(const FieldDescriptor* field) {
|
||||
file->name() == "google/protobuf/descriptor.proto";
|
||||
}
|
||||
|
||||
|
||||
// Used inside Google only -- do not remove.
|
||||
bool IsResponse(const Descriptor* desc) { return false; }
|
||||
|
||||
@ -452,7 +448,6 @@ bool IgnoreField(const FieldDescriptor* field) {
|
||||
return IgnoreExtensionField(field);
|
||||
}
|
||||
|
||||
|
||||
// Do we ignore this message type?
|
||||
bool IgnoreMessage(const Descriptor* d) { return d->options().map_entry(); }
|
||||
|
||||
@ -537,7 +532,6 @@ std::string JSGetterName(const GeneratorOptions& options,
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
std::string JSOneofName(const OneofDescriptor* oneof) {
|
||||
return ToUpperCamel(ParseLowerUnderscore(oneof->name()));
|
||||
}
|
||||
@ -818,23 +812,19 @@ std::string JSFieldDefault(const FieldDescriptor* field) {
|
||||
|
||||
switch (field->cpp_type()) {
|
||||
case FieldDescriptor::CPPTYPE_INT32:
|
||||
return MaybeNumberString(field,
|
||||
StrCat(field->default_value_int32()));
|
||||
return MaybeNumberString(field, StrCat(field->default_value_int32()));
|
||||
case FieldDescriptor::CPPTYPE_UINT32:
|
||||
// The original codegen is in Java, and Java protobufs store unsigned
|
||||
// integer values as signed integer values. In order to exactly match the
|
||||
// output, we need to reinterpret as base-2 signed. Ugh.
|
||||
return MaybeNumberString(
|
||||
field,
|
||||
StrCat(static_cast<int32>(field->default_value_uint32())));
|
||||
field, StrCat(static_cast<int32>(field->default_value_uint32())));
|
||||
case FieldDescriptor::CPPTYPE_INT64:
|
||||
return MaybeNumberString(field,
|
||||
StrCat(field->default_value_int64()));
|
||||
return MaybeNumberString(field, StrCat(field->default_value_int64()));
|
||||
case FieldDescriptor::CPPTYPE_UINT64:
|
||||
// See above note for uint32 -- reinterpreting as signed.
|
||||
return MaybeNumberString(
|
||||
field,
|
||||
StrCat(static_cast<int64>(field->default_value_uint64())));
|
||||
field, StrCat(static_cast<int64>(field->default_value_uint64())));
|
||||
case FieldDescriptor::CPPTYPE_ENUM:
|
||||
return StrCat(field->default_value_enum()->number());
|
||||
case FieldDescriptor::CPPTYPE_BOOL:
|
||||
@ -849,9 +839,10 @@ std::string JSFieldDefault(const FieldDescriptor* field) {
|
||||
bool is_valid = EscapeJSString(field->default_value_string(), &out);
|
||||
if (!is_valid) {
|
||||
// TODO(b/115551870): Decide whether this should be a hard error.
|
||||
GOOGLE_LOG(WARNING) << "The default value for field " << field->full_name()
|
||||
<< " was truncated since it contained invalid UTF-8 or"
|
||||
" codepoints outside the basic multilingual plane.";
|
||||
GOOGLE_LOG(WARNING)
|
||||
<< "The default value for field " << field->full_name()
|
||||
<< " was truncated since it contained invalid UTF-8 or"
|
||||
" codepoints outside the basic multilingual plane.";
|
||||
}
|
||||
return "\"" + out + "\"";
|
||||
} else { // Bytes
|
||||
@ -1114,7 +1105,6 @@ std::string JSBinaryWriterMethodName(const GeneratorOptions& options,
|
||||
JSBinaryReadWriteMethodName(field, /* is_writer = */ true);
|
||||
}
|
||||
|
||||
|
||||
std::string JSTypeTag(const FieldDescriptor* desc) {
|
||||
switch (desc->type()) {
|
||||
case FieldDescriptor::TYPE_DOUBLE:
|
||||
@ -1149,7 +1139,6 @@ std::string JSTypeTag(const FieldDescriptor* desc) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
bool HasRepeatedFields(const GeneratorOptions& options,
|
||||
const Descriptor* desc) {
|
||||
for (int i = 0; i < desc->field_count(); i++) {
|
||||
@ -1638,6 +1627,8 @@ void Generator::GenerateHeader(const GeneratorOptions& options,
|
||||
"/**\n"
|
||||
" * @fileoverview\n"
|
||||
" * @enhanceable\n"
|
||||
// TODO(b/152440355): requireType/requires diverged from internal version.
|
||||
" * @suppress {missingRequire} reports error on implict type usages.\n"
|
||||
" * @suppress {messageConventions} JS Compiler reports an "
|
||||
"error if a variable or\n"
|
||||
" * field starts with 'MSG_' and isn't a translatable "
|
||||
@ -1902,16 +1893,13 @@ void Generator::GenerateRequiresImpl(const GeneratorOptions& options,
|
||||
}
|
||||
}
|
||||
|
||||
bool NamespaceOnly(const Descriptor* desc) {
|
||||
return false;
|
||||
}
|
||||
bool NamespaceOnly(const Descriptor* desc) { return false; }
|
||||
|
||||
void Generator::FindRequiresForMessage(const GeneratorOptions& options,
|
||||
const Descriptor* desc,
|
||||
std::set<std::string>* required,
|
||||
std::set<std::string>* forwards,
|
||||
bool* have_message) const {
|
||||
|
||||
if (!NamespaceOnly(desc)) {
|
||||
*have_message = true;
|
||||
for (int i = 0; i < desc->field_count(); i++) {
|
||||
@ -1960,7 +1948,8 @@ void Generator::FindRequiresForField(const GeneratorOptions& options,
|
||||
void Generator::FindRequiresForExtension(
|
||||
const GeneratorOptions& options, const FieldDescriptor* field,
|
||||
std::set<std::string>* required, std::set<std::string>* forwards) const {
|
||||
if (field->containing_type()->full_name() != "google.protobuf.bridge.MessageSet") {
|
||||
if (field->containing_type()->full_name() !=
|
||||
"google.protobuf.bridge.MessageSet") {
|
||||
required->insert(GetMessagePath(options, field->containing_type()));
|
||||
}
|
||||
FindRequiresForField(options, field, required, forwards);
|
||||
@ -2000,7 +1989,6 @@ void Generator::GenerateClass(const GeneratorOptions& options,
|
||||
printer->Print("\n");
|
||||
GenerateClassFieldInfo(options, printer, desc);
|
||||
|
||||
|
||||
GenerateClassToObject(options, printer, desc);
|
||||
// These must come *before* the extension-field info generation in
|
||||
// GenerateClassRegistration so that references to the binary
|
||||
@ -2084,7 +2072,8 @@ void Generator::GenerateClassConstructorAndDeclareExtensionFieldInfo(
|
||||
const Descriptor* desc) const {
|
||||
if (!NamespaceOnly(desc)) {
|
||||
GenerateClassConstructor(options, printer, desc);
|
||||
if (IsExtendable(desc) && desc->full_name() != "google.protobuf.bridge.MessageSet") {
|
||||
if (IsExtendable(desc) &&
|
||||
desc->full_name() != "google.protobuf.bridge.MessageSet") {
|
||||
GenerateClassExtensionFieldInfo(options, printer, desc);
|
||||
}
|
||||
}
|
||||
@ -2524,7 +2513,6 @@ void Generator::GenerateClassRegistration(const GeneratorOptions& options,
|
||||
GenerateExtension(options, printer, extension);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Generator::GenerateClassFields(const GeneratorOptions& options,
|
||||
@ -2687,8 +2675,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
|
||||
}
|
||||
|
||||
} else {
|
||||
bool untyped =
|
||||
false;
|
||||
bool untyped = false;
|
||||
|
||||
// Simple (primitive) field, either singular or repeated.
|
||||
|
||||
@ -3037,7 +3024,6 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options,
|
||||
io::Printer* printer,
|
||||
const Descriptor* desc) const {
|
||||
@ -3067,36 +3053,36 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options,
|
||||
"$class$.deserializeBinaryFromReader = function(msg, reader) {\n"
|
||||
" while (reader.nextField()) {\n",
|
||||
"class", GetMessagePath(options, desc));
|
||||
printer->Print(
|
||||
" if (reader.isEndGroup()) {\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" var field = reader.getFieldNumber();\n"
|
||||
" switch (field) {\n");
|
||||
|
||||
for (int i = 0; i < desc->field_count(); i++) {
|
||||
if (!IgnoreField(desc->field(i))) {
|
||||
GenerateClassDeserializeBinaryField(options, printer, desc->field(i));
|
||||
}
|
||||
}
|
||||
|
||||
printer->Print(" default:\n");
|
||||
if (IsExtendable(desc)) {
|
||||
printer->Print(
|
||||
" if (reader.isEndGroup()) {\n"
|
||||
" jspb.Message.readBinaryExtension(msg, reader,\n"
|
||||
" $extobj$Binary,\n"
|
||||
" $class$.prototype.getExtension,\n"
|
||||
" $class$.prototype.setExtension);\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" var field = reader.getFieldNumber();\n"
|
||||
" switch (field) {\n");
|
||||
|
||||
for (int i = 0; i < desc->field_count(); i++) {
|
||||
if (!IgnoreField(desc->field(i))) {
|
||||
GenerateClassDeserializeBinaryField(options, printer, desc->field(i));
|
||||
}
|
||||
}
|
||||
|
||||
printer->Print(" default:\n");
|
||||
if (IsExtendable(desc)) {
|
||||
printer->Print(
|
||||
" jspb.Message.readBinaryExtension(msg, reader,\n"
|
||||
" $extobj$Binary,\n"
|
||||
" $class$.prototype.getExtension,\n"
|
||||
" $class$.prototype.setExtension);\n"
|
||||
" break;\n"
|
||||
" }\n",
|
||||
"extobj", JSExtensionsObjectName(options, desc->file(), desc),
|
||||
"class", GetMessagePath(options, desc));
|
||||
} else {
|
||||
printer->Print(
|
||||
" reader.skipField();\n"
|
||||
" break;\n"
|
||||
" }\n");
|
||||
}
|
||||
" }\n",
|
||||
"extobj", JSExtensionsObjectName(options, desc->file(), desc), "class",
|
||||
GetMessagePath(options, desc));
|
||||
} else {
|
||||
printer->Print(
|
||||
" reader.skipField();\n"
|
||||
" break;\n"
|
||||
" }\n");
|
||||
}
|
||||
|
||||
printer->Print(
|
||||
" }\n"
|
||||
@ -3381,9 +3367,8 @@ void Generator::GenerateEnum(const GeneratorOptions& options,
|
||||
for (auto i : valid_index) {
|
||||
const EnumValueDescriptor* value = enumdesc->value(i);
|
||||
printer->Print(" $name$: $value$$comma$\n", "name",
|
||||
ToEnumCase(value->name()), "value",
|
||||
StrCat(value->number()), "comma",
|
||||
(i == valid_index.back()) ? "" : ",");
|
||||
ToEnumCase(value->name()), "value", StrCat(value->number()),
|
||||
"comma", (i == valid_index.back()) ? "" : ",");
|
||||
printer->Annotate("name", value);
|
||||
}
|
||||
|
||||
@ -3424,8 +3409,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
|
||||
"!Object} */ (\n"
|
||||
" $toObject$),\n"
|
||||
" $repeated$);\n",
|
||||
"index", StrCat(field->number()), "name", extension_object_name,
|
||||
"ctor",
|
||||
"index", StrCat(field->number()), "name", extension_object_name, "ctor",
|
||||
(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE
|
||||
? SubmessageTypeRef(options, field)
|
||||
: std::string("null")),
|
||||
@ -3732,7 +3716,6 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (options.output_mode() == GeneratorOptions::kEverythingInOneFile) {
|
||||
// All output should go in a single file.
|
||||
std::string filename = options.output_dir + "/" + options.library +
|
||||
|
@ -198,44 +198,6 @@ int FieldSpaceUsed(const FieldDescriptor* field) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Compute the byte size of in-memory representation of the oneof fields
|
||||
// in default oneof instance.
|
||||
int OneofFieldSpaceUsed(const FieldDescriptor* field) {
|
||||
typedef FieldDescriptor FD; // avoid line wrapping
|
||||
switch (field->cpp_type()) {
|
||||
case FD::CPPTYPE_INT32:
|
||||
return sizeof(int32);
|
||||
case FD::CPPTYPE_INT64:
|
||||
return sizeof(int64);
|
||||
case FD::CPPTYPE_UINT32:
|
||||
return sizeof(uint32);
|
||||
case FD::CPPTYPE_UINT64:
|
||||
return sizeof(uint64);
|
||||
case FD::CPPTYPE_DOUBLE:
|
||||
return sizeof(double);
|
||||
case FD::CPPTYPE_FLOAT:
|
||||
return sizeof(float);
|
||||
case FD::CPPTYPE_BOOL:
|
||||
return sizeof(bool);
|
||||
case FD::CPPTYPE_ENUM:
|
||||
return sizeof(int);
|
||||
|
||||
case FD::CPPTYPE_MESSAGE:
|
||||
return sizeof(Message*);
|
||||
|
||||
case FD::CPPTYPE_STRING:
|
||||
switch (field->options().ctype()) {
|
||||
default:
|
||||
case FieldOptions::STRING:
|
||||
return sizeof(ArenaStringPtr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
GOOGLE_LOG(DFATAL) << "Can't get here.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int DivideRoundingUp(int i, int j) { return (i + (j - 1)) / j; }
|
||||
|
||||
static const int kSafeAlignment = sizeof(uint64);
|
||||
|
@ -87,7 +87,7 @@ inline ExtensionSet* GetExtensionSet(MessageLite* msg, int64 extension_offset) {
|
||||
|
||||
template <typename Type>
|
||||
inline Type* AddField(MessageLite* msg, int64 offset) {
|
||||
static_assert(std::is_standard_layout<Type>::value && std::is_trivial<Type>::value,
|
||||
static_assert(std::is_trivially_copy_assignable<Type>::value,
|
||||
"Do not assign");
|
||||
|
||||
RepeatedField<Type>* repeated = Raw<RepeatedField<Type>>(msg, offset);
|
||||
@ -104,7 +104,7 @@ inline std::string* AddField<std::string>(MessageLite* msg, int64 offset) {
|
||||
|
||||
template <typename Type>
|
||||
inline void AddField(MessageLite* msg, int64 offset, Type value) {
|
||||
static_assert(std::is_standard_layout<Type>::value && std::is_trivial<Type>::value,
|
||||
static_assert(std::is_trivially_copy_assignable<Type>::value,
|
||||
"Do not assign");
|
||||
*AddField<Type>(msg, offset) = value;
|
||||
}
|
||||
@ -126,7 +126,7 @@ inline Type* MutableField(MessageLite* msg, uint32* has_bits,
|
||||
template <typename Type>
|
||||
inline void SetField(MessageLite* msg, uint32* has_bits, uint32 has_bit_index,
|
||||
int64 offset, Type value) {
|
||||
static_assert(std::is_standard_layout<Type>::value && std::is_trivial<Type>::value,
|
||||
static_assert(std::is_trivially_copy_assignable<Type>::value,
|
||||
"Do not assign");
|
||||
*MutableField<Type>(msg, has_bits, has_bit_index, offset) = value;
|
||||
}
|
||||
|
@ -529,6 +529,23 @@ void GenericTypeHandler<std::string>::Merge(const std::string& from,
|
||||
*to = from;
|
||||
}
|
||||
|
||||
// Non-inline variants of std::string specializations for
|
||||
// various InternalMetadata routines.
|
||||
template <>
|
||||
void InternalMetadata::DoClear<std::string>() {
|
||||
mutable_unknown_fields<std::string>()->clear();
|
||||
}
|
||||
|
||||
template <>
|
||||
void InternalMetadata::DoMergeFrom<std::string>(const std::string& other) {
|
||||
mutable_unknown_fields<std::string>()->append(other);
|
||||
}
|
||||
|
||||
template <>
|
||||
void InternalMetadata::DoSwap<std::string>(std::string* other) {
|
||||
mutable_unknown_fields<std::string>()->swap(*other);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
||||
|
@ -146,7 +146,7 @@ class ExplicitlyConstructed {
|
||||
private:
|
||||
// Prefer c++14 aligned_storage, but for compatibility this will do.
|
||||
union AlignedUnion {
|
||||
char space[sizeof(T)];
|
||||
alignas(T) char space[sizeof(T)];
|
||||
int64 align_to_int64;
|
||||
void* align_to_ptr;
|
||||
} union_;
|
||||
|
@ -552,6 +552,34 @@ TEST(MESSAGE_TEST_NAME, IsInitialized) {
|
||||
EXPECT_TRUE(msg.IsInitialized());
|
||||
}
|
||||
|
||||
TEST(MESSAGE_TEST_NAME, IsInitializedSplitBytestream) {
|
||||
UNITTEST::TestRequired ab, c;
|
||||
ab.set_a(1);
|
||||
ab.set_b(2);
|
||||
c.set_c(3);
|
||||
|
||||
// The protobuf represented by the concatenated string has all required
|
||||
// fields (a,b,c) set.
|
||||
std::string bytes =
|
||||
ab.SerializePartialAsString() + c.SerializePartialAsString();
|
||||
|
||||
UNITTEST::TestRequired concatenated;
|
||||
EXPECT_TRUE(concatenated.ParsePartialFromString(bytes));
|
||||
EXPECT_TRUE(concatenated.IsInitialized());
|
||||
|
||||
UNITTEST::TestRequiredForeign fab, fc;
|
||||
fab.mutable_optional_message()->set_a(1);
|
||||
fab.mutable_optional_message()->set_b(2);
|
||||
fc.mutable_optional_message()->set_c(3);
|
||||
|
||||
bytes =
|
||||
fab.SerializePartialAsString() + fc.SerializePartialAsString();
|
||||
|
||||
UNITTEST::TestRequiredForeign fconcatenated;
|
||||
EXPECT_TRUE(fconcatenated.ParsePartialFromString(bytes));
|
||||
EXPECT_TRUE(fconcatenated.IsInitialized());
|
||||
}
|
||||
|
||||
TEST(MESSAGE_FACTORY_TEST_NAME, GeneratedFactoryLookup) {
|
||||
EXPECT_EQ(MessageFactory::generated_factory()->GetPrototype(
|
||||
UNITTEST::TestAllTypes::descriptor()),
|
||||
|
@ -68,7 +68,7 @@ class InternalMetadata {
|
||||
void Delete() {
|
||||
// Note that Delete<> should be called not more than once.
|
||||
if (have_unknown_fields() && arena() == NULL) {
|
||||
delete PtrValue<Container<T>>();
|
||||
DeleteOutOfLineHelper<T>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,6 +202,11 @@ class InternalMetadata {
|
||||
T unknown_fields;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_NOINLINE void DeleteOutOfLineHelper() {
|
||||
delete PtrValue<Container<T>>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_NOINLINE T* mutable_unknown_fields_slow() {
|
||||
Arena* my_arena = arena();
|
||||
@ -221,17 +226,17 @@ class InternalMetadata {
|
||||
// Templated functions.
|
||||
|
||||
template <typename T>
|
||||
void DoClear() {
|
||||
PROTOBUF_NOINLINE void DoClear() {
|
||||
mutable_unknown_fields<T>()->Clear();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DoMergeFrom(const T& other) {
|
||||
PROTOBUF_NOINLINE void DoMergeFrom(const T& other) {
|
||||
mutable_unknown_fields<T>()->MergeFrom(other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DoSwap(T* other) {
|
||||
PROTOBUF_NOINLINE void DoSwap(T* other) {
|
||||
mutable_unknown_fields<T>()->Swap(other);
|
||||
}
|
||||
};
|
||||
@ -239,20 +244,12 @@ class InternalMetadata {
|
||||
// String Template specializations.
|
||||
|
||||
template <>
|
||||
inline void InternalMetadata::DoClear<std::string>() {
|
||||
mutable_unknown_fields<std::string>()->clear();
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT void InternalMetadata::DoClear<std::string>();
|
||||
template <>
|
||||
inline void InternalMetadata::DoMergeFrom<std::string>(
|
||||
const std::string& other) {
|
||||
mutable_unknown_fields<std::string>()->append(other);
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT void InternalMetadata::DoMergeFrom<std::string>(
|
||||
const std::string& other);
|
||||
template <>
|
||||
inline void InternalMetadata::DoSwap<std::string>(std::string* other) {
|
||||
mutable_unknown_fields<std::string>()->swap(*other);
|
||||
}
|
||||
PROTOBUF_EXPORT void InternalMetadata::DoSwap<std::string>(std::string* other);
|
||||
|
||||
// This helper RAII class is needed to efficiently parse unknown fields. We
|
||||
// should only call mutable_unknown_fields if there are actual unknown fields.
|
||||
|
@ -438,7 +438,7 @@ class RepeatedField final {
|
||||
//
|
||||
// The first version executes at 7 cycles per iteration while the second
|
||||
// version near 1 or 2 cycles.
|
||||
template <int = 0, bool = std::is_pod<Element>::value>
|
||||
template <int = 0, bool = std::is_trivial<Element>::value>
|
||||
class FastAdderImpl {
|
||||
public:
|
||||
explicit FastAdderImpl(RepeatedField* rf) : repeated_field_(rf) {
|
||||
@ -501,7 +501,7 @@ namespace internal {
|
||||
// effectively.
|
||||
template <typename Element,
|
||||
bool HasTrivialCopy =
|
||||
std::is_standard_layout<Element>::value && std::is_trivial<Element>::value>
|
||||
std::is_trivially_copy_constructible<Element>::value>
|
||||
struct ElementCopier {
|
||||
void operator()(Element* to, const Element* from, int array_size);
|
||||
};
|
||||
|
@ -39,7 +39,6 @@
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace util {
|
||||
using util::Status;
|
||||
namespace converter {
|
||||
|
||||
namespace {
|
||||
|
@ -52,7 +52,6 @@ namespace util {
|
||||
|
||||
// Allow these symbols to be referenced as util::Status, util::error::* in
|
||||
// this file.
|
||||
using util::Status;
|
||||
namespace error {
|
||||
using util::error::CANCELLED;
|
||||
using util::error::INTERNAL;
|
||||
|
@ -42,13 +42,11 @@
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace util {
|
||||
using util::Status;
|
||||
namespace error {
|
||||
using util::error::INVALID_ARGUMENT;
|
||||
} // namespace error
|
||||
namespace converter {
|
||||
|
||||
using util::Status;
|
||||
|
||||
// Tests for the JSON Stream Parser. These tests are intended to be
|
||||
// comprehensive and cover the following:
|
||||
|
@ -54,7 +54,6 @@ namespace converter {
|
||||
|
||||
using io::CodedOutputStream;
|
||||
using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
|
||||
using util::Status;
|
||||
using util::error::INVALID_ARGUMENT;
|
||||
|
||||
|
||||
|
@ -59,7 +59,6 @@
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace util {
|
||||
using util::Status;
|
||||
namespace error {
|
||||
using util::error::Code;
|
||||
using util::error::INTERNAL;
|
||||
@ -67,7 +66,6 @@ using util::error::INTERNAL;
|
||||
namespace converter {
|
||||
using ::PROTOBUF_NAMESPACE_ID::internal::WireFormat;
|
||||
using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite;
|
||||
using util::Status;
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -74,69 +74,58 @@ class TypeInfo;
|
||||
class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
|
||||
public:
|
||||
struct RenderOptions {
|
||||
RenderOptions() {}
|
||||
RenderOptions() = default;
|
||||
RenderOptions(const RenderOptions&) = default;
|
||||
|
||||
// whether to render enums using lowercamelcase.
|
||||
// Sets whether or not to use lowerCamelCase casing for enum values. If set
|
||||
// to false, enum values are output without any case conversions.
|
||||
//
|
||||
// For example, if we have an enum:
|
||||
// enum Type {
|
||||
// ACTION_AND_ADVENTURE = 1;
|
||||
// }
|
||||
// Type type = 20;
|
||||
//
|
||||
// And this option is set to true. Then the rendered "type" field will have
|
||||
// the string "actionAndAdventure".
|
||||
// {
|
||||
// ...
|
||||
// "type": "actionAndAdventure",
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// If set to false, the rendered "type" field will have the string
|
||||
// "ACTION_AND_ADVENTURE".
|
||||
// {
|
||||
// ...
|
||||
// "type": "ACTION_AND_ADVENTURE",
|
||||
// ...
|
||||
// }
|
||||
bool use_lower_camel_for_enums = false;
|
||||
|
||||
// whether to render enums as ints always. defaults to false.
|
||||
// Sets whether to always output enums as ints, by default this is off, and
|
||||
// enums are rendered as strings.
|
||||
bool use_ints_for_enums = false;
|
||||
|
||||
// whether to preserve proto field names
|
||||
// Whether to preserve proto field names
|
||||
bool preserve_proto_field_names = false;
|
||||
|
||||
};
|
||||
|
||||
ProtoStreamObjectSource(io::CodedInputStream* stream,
|
||||
TypeResolver* type_resolver,
|
||||
const google::protobuf::Type& type)
|
||||
: ProtoStreamObjectSource(stream, type_resolver, type, RenderOptions()) {}
|
||||
ProtoStreamObjectSource(io::CodedInputStream* stream,
|
||||
TypeResolver* type_resolver,
|
||||
const google::protobuf::Type& type,
|
||||
const RenderOptions& render_options = {});
|
||||
const RenderOptions& render_options);
|
||||
|
||||
~ProtoStreamObjectSource() override;
|
||||
|
||||
util::Status NamedWriteTo(StringPiece name,
|
||||
ObjectWriter* ow) const override;
|
||||
|
||||
// Sets whether or not to use lowerCamelCase casing for enum values. If set to
|
||||
// false, enum values are output without any case conversions.
|
||||
//
|
||||
// For example, if we have an enum:
|
||||
// enum Type {
|
||||
// ACTION_AND_ADVENTURE = 1;
|
||||
// }
|
||||
// Type type = 20;
|
||||
//
|
||||
// And this option is set to true. Then the rendered "type" field will have
|
||||
// the string "actionAndAdventure".
|
||||
// {
|
||||
// ...
|
||||
// "type": "actionAndAdventure",
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// If set to false, the rendered "type" field will have the string
|
||||
// "ACTION_AND_ADVENTURE".
|
||||
// {
|
||||
// ...
|
||||
// "type": "ACTION_AND_ADVENTURE",
|
||||
// ...
|
||||
// }
|
||||
void set_use_lower_camel_for_enums(bool value) {
|
||||
render_options_.use_lower_camel_for_enums = value;
|
||||
}
|
||||
|
||||
// Sets whether to always output enums as ints, by default this is off, and
|
||||
// enums are rendered as strings.
|
||||
void set_use_ints_for_enums(bool value) {
|
||||
render_options_.use_ints_for_enums = value;
|
||||
}
|
||||
|
||||
// Sets whether to use original proto field names
|
||||
void set_preserve_proto_field_names(bool value) {
|
||||
render_options_.preserve_proto_field_names = value;
|
||||
}
|
||||
|
||||
// Sets the max recursion depth of proto message to be deserialized. Proto
|
||||
// messages over this depth will fail to be deserialized.
|
||||
// Default value is 64.
|
||||
@ -144,7 +133,6 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
|
||||
max_recursion_depth_ = max_depth;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
// Writes a proto2 Message to the ObjectWriter. When the given end_tag is
|
||||
// found this method will complete, allowing it to be used for parsing both
|
||||
@ -317,7 +305,7 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
|
||||
const google::protobuf::Type& type_;
|
||||
|
||||
|
||||
RenderOptions render_options_;
|
||||
const RenderOptions render_options_;
|
||||
|
||||
// Tracks current recursion depth.
|
||||
mutable int recursion_depth_;
|
||||
|
@ -79,7 +79,6 @@ using proto_util_converter::testing::Proto3Message;
|
||||
using proto_util_converter::testing::StructType;
|
||||
using proto_util_converter::testing::TimestampDuration;
|
||||
using ::testing::_;
|
||||
using util::Status;
|
||||
|
||||
|
||||
namespace {
|
||||
@ -117,12 +116,13 @@ class ProtostreamObjectSourceTest
|
||||
ArrayInputStream arr_stream(proto.data(), proto.size());
|
||||
CodedInputStream in_stream(&arr_stream);
|
||||
|
||||
ProtoStreamObjectSource::RenderOptions render_options;
|
||||
render_options.use_lower_camel_for_enums = use_lower_camel_for_enums_;
|
||||
render_options.use_ints_for_enums = use_ints_for_enums_;
|
||||
render_options.preserve_proto_field_names = use_preserve_proto_field_names_;
|
||||
std::unique_ptr<ProtoStreamObjectSource> os(
|
||||
helper_.NewProtoSource(&in_stream, GetTypeUrl(descriptor)));
|
||||
if (use_lower_camel_for_enums_) os->set_use_lower_camel_for_enums(true);
|
||||
if (use_ints_for_enums_) os->set_use_ints_for_enums(true);
|
||||
if (use_preserve_proto_field_names_)
|
||||
os->set_preserve_proto_field_names(true);
|
||||
helper_.NewProtoSource(&in_stream, GetTypeUrl(descriptor),
|
||||
render_options));
|
||||
os->set_max_recursion_depth(64);
|
||||
return os->WriteTo(&mock_);
|
||||
}
|
||||
|
@ -86,12 +86,13 @@ void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor1,
|
||||
TypeInfo* TypeInfoTestHelper::GetTypeInfo() { return typeinfo_.get(); }
|
||||
|
||||
ProtoStreamObjectSource* TypeInfoTestHelper::NewProtoSource(
|
||||
io::CodedInputStream* coded_input, const std::string& type_url) {
|
||||
io::CodedInputStream* coded_input, const std::string& type_url,
|
||||
ProtoStreamObjectSource::RenderOptions render_options) {
|
||||
const google::protobuf::Type* type = typeinfo_->GetTypeByTypeUrl(type_url);
|
||||
switch (type_) {
|
||||
case USE_TYPE_RESOLVER: {
|
||||
return new ProtoStreamObjectSource(coded_input, type_resolver_.get(),
|
||||
*type);
|
||||
*type, render_options);
|
||||
}
|
||||
}
|
||||
GOOGLE_LOG(FATAL) << "Can not reach here.";
|
||||
|
@ -71,8 +71,9 @@ class TypeInfoTestHelper {
|
||||
// Returns the TypeInfo created after ResetTypeInfo.
|
||||
TypeInfo* GetTypeInfo();
|
||||
|
||||
ProtoStreamObjectSource* NewProtoSource(io::CodedInputStream* coded_input,
|
||||
const std::string& type_url);
|
||||
ProtoStreamObjectSource* NewProtoSource(
|
||||
io::CodedInputStream* coded_input, const std::string& type_url,
|
||||
ProtoStreamObjectSource::RenderOptions render_options = {});
|
||||
|
||||
ProtoStreamObjectWriter* NewProtoWriter(
|
||||
const std::string& type_url, strings::ByteSink* output,
|
||||
|
@ -92,10 +92,12 @@ util::Status BinaryToJsonStream(TypeResolver* resolver,
|
||||
io::CodedInputStream in_stream(binary_input);
|
||||
google::protobuf::Type type;
|
||||
RETURN_IF_ERROR(resolver->ResolveMessageType(type_url, &type));
|
||||
converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type);
|
||||
proto_source.set_use_ints_for_enums(options.always_print_enums_as_ints);
|
||||
proto_source.set_preserve_proto_field_names(
|
||||
options.preserve_proto_field_names);
|
||||
converter::ProtoStreamObjectSource::RenderOptions render_options;
|
||||
render_options.use_ints_for_enums = options.always_print_enums_as_ints;
|
||||
render_options.preserve_proto_field_names =
|
||||
options.preserve_proto_field_names;
|
||||
converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type,
|
||||
render_options);
|
||||
io::CodedOutputStream out_stream(json_output);
|
||||
converter::JsonObjectWriter json_writer(options.add_whitespace ? " " : "",
|
||||
&out_stream);
|
||||
|
@ -1927,11 +1927,6 @@ void MessageDifferencer::StreamReporter::PrintPath(
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDifferencer::StreamReporter::PrintPath(
|
||||
const std::vector<SpecificField>& field_path, bool left_side,
|
||||
const Message& message) {
|
||||
PrintPath(field_path, left_side);
|
||||
}
|
||||
|
||||
void MessageDifferencer::StreamReporter::PrintValue(
|
||||
const Message& message, const std::vector<SpecificField>& field_path,
|
||||
@ -2100,7 +2095,7 @@ void MessageDifferencer::StreamReporter::ReportAdded(
|
||||
const Message& message1, const Message& message2,
|
||||
const std::vector<SpecificField>& field_path) {
|
||||
printer_->Print("added: ");
|
||||
PrintPath(field_path, false, message2);
|
||||
PrintPath(field_path, false);
|
||||
printer_->Print(": ");
|
||||
PrintValue(message2, field_path, false);
|
||||
printer_->Print("\n"); // Print for newlines.
|
||||
@ -2110,7 +2105,7 @@ void MessageDifferencer::StreamReporter::ReportDeleted(
|
||||
const Message& message1, const Message& message2,
|
||||
const std::vector<SpecificField>& field_path) {
|
||||
printer_->Print("deleted: ");
|
||||
PrintPath(field_path, true, message1);
|
||||
PrintPath(field_path, true);
|
||||
printer_->Print(": ");
|
||||
PrintValue(message1, field_path, true);
|
||||
printer_->Print("\n"); // Print for newlines
|
||||
@ -2133,10 +2128,10 @@ void MessageDifferencer::StreamReporter::ReportModified(
|
||||
}
|
||||
|
||||
printer_->Print("modified: ");
|
||||
PrintPath(field_path, true, message1);
|
||||
PrintPath(field_path, true);
|
||||
if (CheckPathChanged(field_path)) {
|
||||
printer_->Print(" -> ");
|
||||
PrintPath(field_path, false, message2);
|
||||
PrintPath(field_path, false);
|
||||
}
|
||||
printer_->Print(": ");
|
||||
PrintValue(message1, field_path, true);
|
||||
@ -2149,9 +2144,9 @@ void MessageDifferencer::StreamReporter::ReportMoved(
|
||||
const Message& message1, const Message& message2,
|
||||
const std::vector<SpecificField>& field_path) {
|
||||
printer_->Print("moved: ");
|
||||
PrintPath(field_path, true, message1);
|
||||
PrintPath(field_path, true);
|
||||
printer_->Print(" -> ");
|
||||
PrintPath(field_path, false, message2);
|
||||
PrintPath(field_path, false);
|
||||
printer_->Print(" : ");
|
||||
PrintValue(message1, field_path, true);
|
||||
printer_->Print("\n"); // Print for newlines.
|
||||
@ -2161,10 +2156,10 @@ void MessageDifferencer::StreamReporter::ReportMatched(
|
||||
const Message& message1, const Message& message2,
|
||||
const std::vector<SpecificField>& field_path) {
|
||||
printer_->Print("matched: ");
|
||||
PrintPath(field_path, true, message1);
|
||||
PrintPath(field_path, true);
|
||||
if (CheckPathChanged(field_path)) {
|
||||
printer_->Print(" -> ");
|
||||
PrintPath(field_path, false, message2);
|
||||
PrintPath(field_path, false);
|
||||
}
|
||||
printer_->Print(" : ");
|
||||
PrintValue(message1, field_path, true);
|
||||
@ -2175,10 +2170,10 @@ void MessageDifferencer::StreamReporter::ReportIgnored(
|
||||
const Message& message1, const Message& message2,
|
||||
const std::vector<SpecificField>& field_path) {
|
||||
printer_->Print("ignored: ");
|
||||
PrintPath(field_path, true, message1);
|
||||
PrintPath(field_path, true);
|
||||
if (CheckPathChanged(field_path)) {
|
||||
printer_->Print(" -> ");
|
||||
PrintPath(field_path, false, message2);
|
||||
PrintPath(field_path, false);
|
||||
}
|
||||
printer_->Print("\n"); // Print for newlines.
|
||||
}
|
||||
@ -2193,10 +2188,10 @@ void MessageDifferencer::StreamReporter::ReportUnknownFieldIgnored(
|
||||
const Message& message1, const Message& message2,
|
||||
const std::vector<SpecificField>& field_path) {
|
||||
printer_->Print("ignored: ");
|
||||
PrintPath(field_path, true, message1);
|
||||
PrintPath(field_path, true);
|
||||
if (CheckPathChanged(field_path)) {
|
||||
printer_->Print(" -> ");
|
||||
PrintPath(field_path, false, message2);
|
||||
PrintPath(field_path, false);
|
||||
}
|
||||
printer_->Print("\n"); // Print for newlines.
|
||||
}
|
||||
|
@ -673,11 +673,6 @@ class PROTOBUF_EXPORT MessageDifferencer {
|
||||
void SetMessages(const Message& message1, const Message& message2);
|
||||
|
||||
protected:
|
||||
// Prints the specified path of fields to the buffer. message is used to
|
||||
// print map keys.
|
||||
virtual void PrintPath(const std::vector<SpecificField>& field_path,
|
||||
bool left_side, const Message& message);
|
||||
|
||||
// Prints the specified path of fields to the buffer.
|
||||
virtual void PrintPath(const std::vector<SpecificField>& field_path,
|
||||
bool left_side);
|
||||
|
Loading…
Reference in New Issue
Block a user