proto3_test.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. goog.require('goog.crypt.base64');
  31. goog.require('goog.testing.asserts');
  32. // CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
  33. goog.require('proto.jspb.test.ForeignMessage');
  34. // CommonJS-LoadFromFile: proto3_test_pb proto.jspb.test
  35. goog.require('proto.jspb.test.Proto3Enum');
  36. goog.require('proto.jspb.test.TestProto3');
  37. // CommonJS-LoadFromFile: google/protobuf/any_pb proto.google.protobuf
  38. goog.require('proto.google.protobuf.Any');
  39. // CommonJS-LoadFromFile: google/protobuf/timestamp_pb proto.google.protobuf
  40. goog.require('proto.google.protobuf.Timestamp');
  41. // CommonJS-LoadFromFile: google/protobuf/struct_pb proto.google.protobuf
  42. goog.require('proto.google.protobuf.Struct');
  43. goog.require('jspb.Message');
  44. var BYTES = new Uint8Array([1, 2, 8, 9]);
  45. var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES);
  46. /**
  47. * Helper: compare a bytes field to an expected value
  48. * @param {Uint8Array|string} arr
  49. * @param {Uint8Array} expected
  50. * @return {boolean}
  51. */
  52. function bytesCompare(arr, expected) {
  53. if (typeof arr === 'string') {
  54. arr = goog.crypt.base64.decodeStringToUint8Array(arr);
  55. }
  56. if (arr.length != expected.length) {
  57. return false;
  58. }
  59. for (var i = 0; i < arr.length; i++) {
  60. if (arr[i] != expected[i]) {
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66. describe('proto3Test', function() {
  67. /**
  68. * Test default values don't affect equality test.
  69. */
  70. it('testEqualsProto3', function() {
  71. var msg1 = new proto.jspb.test.TestProto3();
  72. var msg2 = new proto.jspb.test.TestProto3();
  73. msg2.setSingularString('');
  74. assertTrue(jspb.Message.equals(msg1, msg2));
  75. });
  76. /**
  77. * Test setting when a field has default semantics.
  78. */
  79. it('testSetProto3ToValueAndBackToDefault', function() {
  80. var msg = new proto.jspb.test.TestProto3();
  81. // Setting should work normally.
  82. msg.setSingularString('optionalString');
  83. assertEquals(msg.getSingularString(), 'optionalString');
  84. // Clearing should work too ...
  85. msg.setSingularString('');
  86. assertEquals(msg.getSingularString(), '');
  87. // ... and shouldn't affect the equality with a brand new message.
  88. assertTrue(jspb.Message.equals(msg, new proto.jspb.test.TestProto3()));
  89. });
  90. /**
  91. * Test defaults for proto3 message fields.
  92. */
  93. it('testProto3FieldDefaults', function() {
  94. var msg = new proto.jspb.test.TestProto3();
  95. assertEquals(msg.getSingularInt32(), 0);
  96. assertEquals(msg.getSingularInt64(), 0);
  97. assertEquals(msg.getSingularUint32(), 0);
  98. assertEquals(msg.getSingularUint64(), 0);
  99. assertEquals(msg.getSingularSint32(), 0);
  100. assertEquals(msg.getSingularSint64(), 0);
  101. assertEquals(msg.getSingularFixed32(), 0);
  102. assertEquals(msg.getSingularFixed64(), 0);
  103. assertEquals(msg.getSingularSfixed32(), 0);
  104. assertEquals(msg.getSingularSfixed64(), 0);
  105. assertEquals(msg.getSingularFloat(), 0);
  106. assertEquals(msg.getSingularDouble(), 0);
  107. assertEquals(msg.getSingularString(), '');
  108. // TODO(b/26173701): when we change bytes fields default getter to return
  109. // Uint8Array, we'll want to switch this assertion to match the u8 case.
  110. assertEquals(typeof msg.getSingularBytes(), 'string');
  111. assertEquals(msg.getSingularBytes_asU8() instanceof Uint8Array, true);
  112. assertEquals(typeof msg.getSingularBytes_asB64(), 'string');
  113. assertEquals(msg.getSingularBytes().length, 0);
  114. assertEquals(msg.getSingularBytes_asU8().length, 0);
  115. assertEquals(msg.getSingularBytes_asB64(), '');
  116. assertEquals(
  117. msg.getSingularForeignEnum(), proto.jspb.test.Proto3Enum.PROTO3_FOO);
  118. assertEquals(msg.getSingularForeignMessage(), undefined);
  119. assertEquals(msg.getSingularForeignMessage(), undefined);
  120. assertEquals(msg.getRepeatedInt32List().length, 0);
  121. assertEquals(msg.getRepeatedInt64List().length, 0);
  122. assertEquals(msg.getRepeatedUint32List().length, 0);
  123. assertEquals(msg.getRepeatedUint64List().length, 0);
  124. assertEquals(msg.getRepeatedSint32List().length, 0);
  125. assertEquals(msg.getRepeatedSint64List().length, 0);
  126. assertEquals(msg.getRepeatedFixed32List().length, 0);
  127. assertEquals(msg.getRepeatedFixed64List().length, 0);
  128. assertEquals(msg.getRepeatedSfixed32List().length, 0);
  129. assertEquals(msg.getRepeatedSfixed64List().length, 0);
  130. assertEquals(msg.getRepeatedFloatList().length, 0);
  131. assertEquals(msg.getRepeatedDoubleList().length, 0);
  132. assertEquals(msg.getRepeatedStringList().length, 0);
  133. assertEquals(msg.getRepeatedBytesList().length, 0);
  134. assertEquals(msg.getRepeatedForeignEnumList().length, 0);
  135. assertEquals(msg.getRepeatedForeignMessageList().length, 0);
  136. });
  137. /**
  138. * Test presence for proto3 optional fields.
  139. */
  140. it('testProto3Optional', function() {
  141. var msg = new proto.jspb.test.TestProto3();
  142. assertEquals(msg.getOptionalInt32(), 0);
  143. assertEquals(msg.getOptionalInt64(), 0);
  144. assertEquals(msg.getOptionalUint32(), 0);
  145. assertEquals(msg.getOptionalUint64(), 0);
  146. assertEquals(msg.getOptionalSint32(), 0);
  147. assertEquals(msg.getOptionalSint64(), 0);
  148. assertEquals(msg.getOptionalFixed32(), 0);
  149. assertEquals(msg.getOptionalFixed64(), 0);
  150. assertEquals(msg.getOptionalSfixed32(), 0);
  151. assertEquals(msg.getOptionalSfixed64(), 0);
  152. assertEquals(msg.getOptionalFloat(), 0);
  153. assertEquals(msg.getOptionalDouble(), 0);
  154. assertEquals(msg.getOptionalString(), '');
  155. // TODO(b/26173701): when we change bytes fields default getter to return
  156. // Uint8Array, we'll want to switch this assertion to match the u8 case.
  157. assertEquals(typeof msg.getOptionalBytes(), 'string');
  158. assertEquals(msg.getOptionalBytes_asU8() instanceof Uint8Array, true);
  159. assertEquals(typeof msg.getOptionalBytes_asB64(), 'string');
  160. assertEquals(msg.getOptionalBytes().length, 0);
  161. assertEquals(msg.getOptionalBytes_asU8().length, 0);
  162. assertEquals(msg.getOptionalBytes_asB64(), '');
  163. assertEquals(
  164. msg.getOptionalForeignEnum(), proto.jspb.test.Proto3Enum.PROTO3_FOO);
  165. assertEquals(msg.getOptionalForeignMessage(), undefined);
  166. assertEquals(msg.getOptionalForeignMessage(), undefined);
  167. // Serializing an empty proto yields the empty string.
  168. assertEquals(msg.serializeBinary().length, 0);
  169. // Values start as unset, but can be explicitly set even to default values
  170. // like 0.
  171. assertFalse(msg.hasOptionalInt32());
  172. msg.setOptionalInt32(0);
  173. assertTrue(msg.hasOptionalInt32());
  174. assertFalse(msg.hasOptionalInt64());
  175. msg.setOptionalInt64(0);
  176. assertTrue(msg.hasOptionalInt64());
  177. assertFalse(msg.hasOptionalString());
  178. msg.setOptionalString('');
  179. assertTrue(msg.hasOptionalString());
  180. // Now the proto will have a non-zero size, even though its values are 0.
  181. var serialized = msg.serializeBinary();
  182. assertNotEquals(serialized.length, 0);
  183. var msg2 = proto.jspb.test.TestProto3.deserializeBinary(serialized);
  184. assertTrue(msg2.hasOptionalInt32());
  185. assertTrue(msg2.hasOptionalInt64());
  186. assertTrue(msg2.hasOptionalString());
  187. // We can clear fields to go back to empty.
  188. msg2.clearOptionalInt32();
  189. assertFalse(msg2.hasOptionalInt32());
  190. msg2.clearOptionalString();
  191. assertFalse(msg2.hasOptionalString());
  192. });
  193. /**
  194. * Test that all fields can be set ,and read via a serialization roundtrip.
  195. */
  196. it('testProto3FieldSetGet', function() {
  197. var msg = new proto.jspb.test.TestProto3();
  198. msg.setSingularInt32(-42);
  199. msg.setSingularInt64(-0x7fffffff00000000);
  200. msg.setSingularUint32(0x80000000);
  201. msg.setSingularUint64(0xf000000000000000);
  202. msg.setSingularSint32(-100);
  203. msg.setSingularSint64(-0x8000000000000000);
  204. msg.setSingularFixed32(1234);
  205. msg.setSingularFixed64(0x1234567800000000);
  206. msg.setSingularSfixed32(-1234);
  207. msg.setSingularSfixed64(-0x1234567800000000);
  208. msg.setSingularFloat(1.5);
  209. msg.setSingularDouble(-1.5);
  210. msg.setSingularBool(true);
  211. msg.setSingularString('hello world');
  212. msg.setSingularBytes(BYTES);
  213. var submsg = new proto.jspb.test.ForeignMessage();
  214. submsg.setC(16);
  215. msg.setSingularForeignMessage(submsg);
  216. msg.setSingularForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
  217. msg.setRepeatedInt32List([-42]);
  218. msg.setRepeatedInt64List([-0x7fffffff00000000]);
  219. msg.setRepeatedUint32List([0x80000000]);
  220. msg.setRepeatedUint64List([0xf000000000000000]);
  221. msg.setRepeatedSint32List([-100]);
  222. msg.setRepeatedSint64List([-0x8000000000000000]);
  223. msg.setRepeatedFixed32List([1234]);
  224. msg.setRepeatedFixed64List([0x1234567800000000]);
  225. msg.setRepeatedSfixed32List([-1234]);
  226. msg.setRepeatedSfixed64List([-0x1234567800000000]);
  227. msg.setRepeatedFloatList([1.5]);
  228. msg.setRepeatedDoubleList([-1.5]);
  229. msg.setRepeatedBoolList([true]);
  230. msg.setRepeatedStringList(['hello world']);
  231. msg.setRepeatedBytesList([BYTES]);
  232. submsg = new proto.jspb.test.ForeignMessage();
  233. submsg.setC(1000);
  234. msg.setRepeatedForeignMessageList([submsg]);
  235. msg.setRepeatedForeignEnumList([proto.jspb.test.Proto3Enum.PROTO3_BAR]);
  236. msg.setOneofString('asdf');
  237. var serialized = msg.serializeBinary();
  238. msg = proto.jspb.test.TestProto3.deserializeBinary(serialized);
  239. assertEquals(msg.getSingularInt32(), -42);
  240. assertEquals(msg.getSingularInt64(), -0x7fffffff00000000);
  241. assertEquals(msg.getSingularUint32(), 0x80000000);
  242. assertEquals(msg.getSingularUint64(), 0xf000000000000000);
  243. assertEquals(msg.getSingularSint32(), -100);
  244. assertEquals(msg.getSingularSint64(), -0x8000000000000000);
  245. assertEquals(msg.getSingularFixed32(), 1234);
  246. assertEquals(msg.getSingularFixed64(), 0x1234567800000000);
  247. assertEquals(msg.getSingularSfixed32(), -1234);
  248. assertEquals(msg.getSingularSfixed64(), -0x1234567800000000);
  249. assertEquals(msg.getSingularFloat(), 1.5);
  250. assertEquals(msg.getSingularDouble(), -1.5);
  251. assertEquals(msg.getSingularBool(), true);
  252. assertEquals(msg.getSingularString(), 'hello world');
  253. assertEquals(true, bytesCompare(msg.getSingularBytes(), BYTES));
  254. assertEquals(msg.getSingularForeignMessage().getC(), 16);
  255. assertEquals(
  256. msg.getSingularForeignEnum(), proto.jspb.test.Proto3Enum.PROTO3_BAR);
  257. assertElementsEquals(msg.getRepeatedInt32List(), [-42]);
  258. assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]);
  259. assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]);
  260. assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]);
  261. assertElementsEquals(msg.getRepeatedSint32List(), [-100]);
  262. assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]);
  263. assertElementsEquals(msg.getRepeatedFixed32List(), [1234]);
  264. assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]);
  265. assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]);
  266. assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]);
  267. assertElementsEquals(msg.getRepeatedFloatList(), [1.5]);
  268. assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]);
  269. assertElementsEquals(msg.getRepeatedBoolList(), [true]);
  270. assertElementsEquals(msg.getRepeatedStringList(), ['hello world']);
  271. assertEquals(msg.getRepeatedBytesList().length, 1);
  272. assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], BYTES));
  273. assertEquals(msg.getRepeatedForeignMessageList().length, 1);
  274. assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000);
  275. assertElementsEquals(
  276. msg.getRepeatedForeignEnumList(),
  277. [proto.jspb.test.Proto3Enum.PROTO3_BAR]);
  278. assertEquals(msg.getOneofString(), 'asdf');
  279. });
  280. /**
  281. * Test that oneofs continue to have a notion of field presence.
  282. */
  283. it('testOneofs', function() {
  284. // Default instance.
  285. var msg = new proto.jspb.test.TestProto3();
  286. assertEquals(msg.getOneofUint32(), 0);
  287. assertEquals(msg.getOneofForeignMessage(), undefined);
  288. assertEquals(msg.getOneofString(), '');
  289. assertEquals(msg.getOneofBytes(), '');
  290. assertFalse(msg.hasOneofUint32());
  291. assertFalse(msg.hasOneofForeignMessage());
  292. assertFalse(msg.hasOneofString());
  293. assertFalse(msg.hasOneofBytes());
  294. // Integer field.
  295. msg.setOneofUint32(42);
  296. assertEquals(msg.getOneofUint32(), 42);
  297. assertEquals(msg.getOneofForeignMessage(), undefined);
  298. assertEquals(msg.getOneofString(), '');
  299. assertEquals(msg.getOneofBytes(), '');
  300. assertTrue(msg.hasOneofUint32());
  301. assertFalse(msg.hasOneofForeignMessage());
  302. assertFalse(msg.hasOneofString());
  303. assertFalse(msg.hasOneofBytes());
  304. // Sub-message field.
  305. var submsg = new proto.jspb.test.ForeignMessage();
  306. msg.setOneofForeignMessage(submsg);
  307. assertEquals(msg.getOneofUint32(), 0);
  308. assertEquals(msg.getOneofForeignMessage(), submsg);
  309. assertEquals(msg.getOneofString(), '');
  310. assertEquals(msg.getOneofBytes(), '');
  311. assertFalse(msg.hasOneofUint32());
  312. assertTrue(msg.hasOneofForeignMessage());
  313. assertFalse(msg.hasOneofString());
  314. assertFalse(msg.hasOneofBytes());
  315. // String field.
  316. msg.setOneofString('hello');
  317. assertEquals(msg.getOneofUint32(), 0);
  318. assertEquals(msg.getOneofForeignMessage(), undefined);
  319. assertEquals(msg.getOneofString(), 'hello');
  320. assertEquals(msg.getOneofBytes(), '');
  321. assertFalse(msg.hasOneofUint32());
  322. assertFalse(msg.hasOneofForeignMessage());
  323. assertTrue(msg.hasOneofString());
  324. assertFalse(msg.hasOneofBytes());
  325. // Bytes field.
  326. msg.setOneofBytes(goog.crypt.base64.encodeString('\u00FF\u00FF'));
  327. assertEquals(msg.getOneofUint32(), 0);
  328. assertEquals(msg.getOneofForeignMessage(), undefined);
  329. assertEquals(msg.getOneofString(), '');
  330. assertEquals(
  331. msg.getOneofBytes_asB64(),
  332. goog.crypt.base64.encodeString('\u00FF\u00FF'));
  333. assertFalse(msg.hasOneofUint32());
  334. assertFalse(msg.hasOneofForeignMessage());
  335. assertFalse(msg.hasOneofString());
  336. assertTrue(msg.hasOneofBytes());
  337. });
  338. /**
  339. * Test that "default"-valued primitive fields are not emitted on the wire.
  340. */
  341. it('testNoSerializeDefaults', function() {
  342. var msg = new proto.jspb.test.TestProto3();
  343. // Set each primitive to a non-default value, then back to its default, to
  344. // ensure that the serialization is actually checking the value and not just
  345. // whether it has ever been set.
  346. msg.setSingularInt32(42);
  347. msg.setSingularInt32(0);
  348. msg.setSingularDouble(3.14);
  349. msg.setSingularDouble(0.0);
  350. msg.setSingularBool(true);
  351. msg.setSingularBool(false);
  352. msg.setSingularString('hello world');
  353. msg.setSingularString('');
  354. msg.setSingularBytes(goog.crypt.base64.encodeString('\u00FF\u00FF'));
  355. msg.setSingularBytes('');
  356. msg.setSingularForeignMessage(new proto.jspb.test.ForeignMessage());
  357. msg.setSingularForeignMessage(null);
  358. msg.setSingularForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
  359. msg.setSingularForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO);
  360. msg.setOneofUint32(32);
  361. msg.clearOneofUint32();
  362. var serialized = msg.serializeBinary();
  363. assertEquals(0, serialized.length);
  364. });
  365. /**
  366. * Test that base64 string and Uint8Array are interchangeable in bytes fields.
  367. */
  368. it('testBytesFieldsInterop', function() {
  369. var msg = new proto.jspb.test.TestProto3();
  370. // Set as a base64 string and check all the getters work.
  371. msg.setSingularBytes(BYTES_B64);
  372. assertTrue(bytesCompare(msg.getSingularBytes_asU8(), BYTES));
  373. assertTrue(bytesCompare(msg.getSingularBytes_asB64(), BYTES));
  374. assertTrue(bytesCompare(msg.getSingularBytes(), BYTES));
  375. // Test binary serialize round trip doesn't break it.
  376. msg = proto.jspb.test.TestProto3.deserializeBinary(msg.serializeBinary());
  377. assertTrue(bytesCompare(msg.getSingularBytes_asU8(), BYTES));
  378. assertTrue(bytesCompare(msg.getSingularBytes_asB64(), BYTES));
  379. assertTrue(bytesCompare(msg.getSingularBytes(), BYTES));
  380. msg = new proto.jspb.test.TestProto3();
  381. // Set as a Uint8Array and check all the getters work.
  382. msg.setSingularBytes(BYTES);
  383. assertTrue(bytesCompare(msg.getSingularBytes_asU8(), BYTES));
  384. assertTrue(bytesCompare(msg.getSingularBytes_asB64(), BYTES));
  385. assertTrue(bytesCompare(msg.getSingularBytes(), BYTES));
  386. });
  387. it('testTimestampWellKnownType', function() {
  388. var msg = new proto.google.protobuf.Timestamp();
  389. msg.fromDate(new Date(123456789));
  390. assertEquals(123456, msg.getSeconds());
  391. assertEquals(789000000, msg.getNanos());
  392. var date = msg.toDate();
  393. assertEquals(123456789, date.getTime());
  394. var anotherMsg = proto.google.protobuf.Timestamp.fromDate(date);
  395. assertEquals(msg.getSeconds(), anotherMsg.getSeconds());
  396. assertEquals(msg.getNanos(), anotherMsg.getNanos());
  397. });
  398. it('testStructWellKnownType', function() {
  399. var jsObj = {
  400. abc: 'def',
  401. number: 12345.678,
  402. nullKey: null,
  403. boolKey: true,
  404. listKey: [1, null, true, false, 'abc'],
  405. structKey: {foo: 'bar', somenum: 123},
  406. complicatedKey: [{xyz: {abc: [3, 4, null, false]}}, 'zzz']
  407. };
  408. var struct = proto.google.protobuf.Struct.fromJavaScript(jsObj);
  409. var jsObj2 = struct.toJavaScript();
  410. assertEquals('def', jsObj2.abc);
  411. assertEquals(12345.678, jsObj2.number);
  412. assertEquals(null, jsObj2.nullKey);
  413. assertEquals(true, jsObj2.boolKey);
  414. assertEquals('abc', jsObj2.listKey[4]);
  415. assertEquals('bar', jsObj2.structKey.foo);
  416. assertEquals(4, jsObj2.complicatedKey[0].xyz.abc[1]);
  417. });
  418. });