Skip to content

Commit af62fde

Browse files
habermanTeBoring
authored andcommitted
Fix for maps_test.js in JavaScript. (protocolbuffers#2145)
Had to strip out some JSPB-format test code, but also added some .proto test messages that had been improperly stripped out.
1 parent e3f0689 commit af62fde

File tree

2 files changed

+31
-63
lines changed

2 files changed

+31
-63
lines changed

js/maps_test.js

+5-63
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@
3030

3131
goog.require('goog.testing.asserts');
3232
goog.require('goog.userAgent');
33+
34+
// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
3335
goog.require('proto.jspb.test.MapValueEnum');
3436
goog.require('proto.jspb.test.MapValueMessage');
35-
goog.require('proto.jspb.test.MapValueMessageNoBinary');
3637
goog.require('proto.jspb.test.TestMapFields');
38+
39+
// CommonJS-LoadFromFile: test_pb proto.jspb.test
40+
goog.require('proto.jspb.test.MapValueMessageNoBinary');
3741
goog.require('proto.jspb.test.TestMapFieldsNoBinary');
3842

3943
/**
@@ -258,64 +262,6 @@ function makeTests(msgInfo, submessageCtor, suffix) {
258262
});
259263
}
260264

261-
262-
/**
263-
* Tests serialization and deserialization in JSPB format.
264-
*/
265-
it('testJSPBFormat' + suffix, function() {
266-
var msg = new msgInfo.constructor();
267-
fillMapFields(msg);
268-
var serialized = msg.serialize();
269-
var decoded = msgInfo.deserialize(serialized);
270-
checkMapFields(decoded);
271-
});
272-
273-
/**
274-
* Tests serialization and deserialization in JSPB format, when there is
275-
* a submessage that also contains map entries. This tests recursive
276-
* sync.
277-
*/
278-
it('testJSPBFormatNested' + suffix, function() {
279-
var submsg = new msgInfo.constructor();
280-
var mapValue = new msgInfo.constructor();
281-
var msg = new msgInfo.constructor();
282-
283-
msg.getMapStringTestmapfieldsMap().set('test', mapValue);
284-
msg.setTestMapFields(submsg);
285-
286-
fillMapFields(submsg);
287-
fillMapFields(msg);
288-
fillMapFields(mapValue);
289-
290-
var serialized = msg.serialize();
291-
292-
var decoded = msgInfo.deserialize(serialized);
293-
checkMapFields(decoded);
294-
295-
var decodedSubmsg = decoded.getTestMapFields();
296-
assertNotNull(decodedSubmsg);
297-
checkMapFields(decodedSubmsg);
298-
299-
var decodedMapValue = decoded.getMapStringTestmapfieldsMap().get('test');
300-
assertNotNull(decodedMapValue);
301-
checkMapFields(decodedMapValue);
302-
});
303-
304-
/**
305-
* Tests toObject()/fromObject().
306-
*/
307-
it('testToFromObject' + suffix, function() {
308-
var msg = new msgInfo.constructor();
309-
fillMapFields(msg);
310-
var obj = msg.toObject();
311-
var decoded = msgInfo.fromObject(obj);
312-
checkMapFields(decoded);
313-
obj = msgInfo.deserialize(msg.serialize()).toObject();
314-
decoded = msgInfo.fromObject(obj);
315-
checkMapFields(decoded);
316-
});
317-
318-
319265
/**
320266
* Exercises the lazy map<->underlying array sync.
321267
*/
@@ -346,14 +292,10 @@ function makeTests(msgInfo, submessageCtor, suffix) {
346292
describe('mapsTest', function() {
347293
makeTests({
348294
constructor: proto.jspb.test.TestMapFields,
349-
fromObject: proto.jspb.test.TestMapFields.fromObject,
350-
deserialize: proto.jspb.test.TestMapFields.deserialize,
351295
deserializeBinary: proto.jspb.test.TestMapFields.deserializeBinary
352296
}, proto.jspb.test.MapValueMessage, "_Binary");
353297
makeTests({
354298
constructor: proto.jspb.test.TestMapFieldsNoBinary,
355-
fromObject: proto.jspb.test.TestMapFieldsNoBinary.fromObject,
356-
deserialize: proto.jspb.test.TestMapFieldsNoBinary.deserialize,
357299
deserializeBinary: null
358300
}, proto.jspb.test.MapValueMessageNoBinary, "_NoBinary");
359301
});

js/test.proto

+26
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,29 @@ message TestEndsWithBytes {
234234
optional bytes data = 2;
235235
}
236236

237+
message TestMapFieldsNoBinary {
238+
map<string, string> map_string_string = 1;
239+
map<string, int32> map_string_int32 = 2;
240+
map<string, int64> map_string_int64 = 3;
241+
map<string, bool> map_string_bool = 4;
242+
map<string, double> map_string_double = 5;
243+
map<string, MapValueEnumNoBinary> map_string_enum = 6;
244+
map<string, MapValueMessageNoBinary> map_string_msg = 7;
245+
246+
map<int32, string> map_int32_string = 8;
247+
map<int64, string> map_int64_string = 9;
248+
map<bool, string> map_bool_string = 10;
249+
250+
optional TestMapFieldsNoBinary test_map_fields = 11;
251+
map<string, TestMapFieldsNoBinary> map_string_testmapfields = 12;
252+
}
253+
254+
enum MapValueEnumNoBinary {
255+
MAP_VALUE_FOO_NOBINARY = 0;
256+
MAP_VALUE_BAR_NOBINARY = 1;
257+
MAP_VALUE_BAZ_NOBINARY = 2;
258+
}
259+
260+
message MapValueMessageNoBinary {
261+
optional int32 foo = 1;
262+
}

0 commit comments

Comments
 (0)