1ffe3c632Sopenharmony_ci// Protocol Buffers - Google's data interchange format 2ffe3c632Sopenharmony_ci// Copyright 2008 Google Inc. All rights reserved. 3ffe3c632Sopenharmony_ci// https://developers.google.com/protocol-buffers/ 4ffe3c632Sopenharmony_ci// 5ffe3c632Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 6ffe3c632Sopenharmony_ci// modification, are permitted provided that the following conditions are 7ffe3c632Sopenharmony_ci// met: 8ffe3c632Sopenharmony_ci// 9ffe3c632Sopenharmony_ci// * Redistributions of source code must retain the above copyright 10ffe3c632Sopenharmony_ci// notice, this list of conditions and the following disclaimer. 11ffe3c632Sopenharmony_ci// * Redistributions in binary form must reproduce the above 12ffe3c632Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 13ffe3c632Sopenharmony_ci// in the documentation and/or other materials provided with the 14ffe3c632Sopenharmony_ci// distribution. 15ffe3c632Sopenharmony_ci// * Neither the name of Google Inc. nor the names of its 16ffe3c632Sopenharmony_ci// contributors may be used to endorse or promote products derived from 17ffe3c632Sopenharmony_ci// this software without specific prior written permission. 18ffe3c632Sopenharmony_ci// 19ffe3c632Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20ffe3c632Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21ffe3c632Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22ffe3c632Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23ffe3c632Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24ffe3c632Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25ffe3c632Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26ffe3c632Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27ffe3c632Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28ffe3c632Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29ffe3c632Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30ffe3c632Sopenharmony_ci 31ffe3c632Sopenharmony_cigoog.setTestOnly(); 32ffe3c632Sopenharmony_ci 33ffe3c632Sopenharmony_cigoog.require('goog.testing.asserts'); 34ffe3c632Sopenharmony_ci 35ffe3c632Sopenharmony_ci// CommonJS-LoadFromFile: google-protobuf 36ffe3c632Sopenharmony_cigoog.require('jspb.debug'); 37ffe3c632Sopenharmony_ci 38ffe3c632Sopenharmony_ci// CommonJS-LoadFromFile: test_pb 39ffe3c632Sopenharmony_cigoog.require('proto.jspb.test.HasExtensions'); 40ffe3c632Sopenharmony_cigoog.require('proto.jspb.test.IsExtension'); 41ffe3c632Sopenharmony_cigoog.require('proto.jspb.test.MapValueMessageNoBinary'); 42ffe3c632Sopenharmony_cigoog.require('proto.jspb.test.Simple1'); 43ffe3c632Sopenharmony_cigoog.require('proto.jspb.test.TestMapFieldsNoBinary'); 44ffe3c632Sopenharmony_ci 45ffe3c632Sopenharmony_ci 46ffe3c632Sopenharmony_ci// CommonJS-LoadFromFile: testbinary_pb 47ffe3c632Sopenharmony_cigoog.require('proto.jspb.test.TestAllTypes'); 48ffe3c632Sopenharmony_ci 49ffe3c632Sopenharmony_cidescribe('debugTest', function() { 50ffe3c632Sopenharmony_ci it('testSimple1', function() { 51ffe3c632Sopenharmony_ci if (COMPILED) { 52ffe3c632Sopenharmony_ci return; 53ffe3c632Sopenharmony_ci } 54ffe3c632Sopenharmony_ci var message = new proto.jspb.test.Simple1(); 55ffe3c632Sopenharmony_ci message.setAString('foo'); 56ffe3c632Sopenharmony_ci assertObjectEquals({ 57ffe3c632Sopenharmony_ci $name: 'proto.jspb.test.Simple1', 58ffe3c632Sopenharmony_ci 'aString': 'foo', 59ffe3c632Sopenharmony_ci 'aRepeatedStringList': [] 60ffe3c632Sopenharmony_ci }, jspb.debug.dump(message)); 61ffe3c632Sopenharmony_ci 62ffe3c632Sopenharmony_ci message.setABoolean(true); 63ffe3c632Sopenharmony_ci message.setARepeatedStringList(['1', '2']); 64ffe3c632Sopenharmony_ci 65ffe3c632Sopenharmony_ci assertObjectEquals({ 66ffe3c632Sopenharmony_ci $name: 'proto.jspb.test.Simple1', 67ffe3c632Sopenharmony_ci 'aString': 'foo', 68ffe3c632Sopenharmony_ci 'aRepeatedStringList': ['1', '2'], 69ffe3c632Sopenharmony_ci 'aBoolean': true 70ffe3c632Sopenharmony_ci }, jspb.debug.dump(message)); 71ffe3c632Sopenharmony_ci 72ffe3c632Sopenharmony_ci message.clearAString(); 73ffe3c632Sopenharmony_ci 74ffe3c632Sopenharmony_ci assertObjectEquals({ 75ffe3c632Sopenharmony_ci $name: 'proto.jspb.test.Simple1', 76ffe3c632Sopenharmony_ci 'aRepeatedStringList': ['1', '2'], 77ffe3c632Sopenharmony_ci 'aBoolean': true 78ffe3c632Sopenharmony_ci }, jspb.debug.dump(message)); 79ffe3c632Sopenharmony_ci }); 80ffe3c632Sopenharmony_ci 81ffe3c632Sopenharmony_ci it('testBytes', function() { 82ffe3c632Sopenharmony_ci if (COMPILED || typeof Uint8Array == 'undefined') { 83ffe3c632Sopenharmony_ci return; 84ffe3c632Sopenharmony_ci } 85ffe3c632Sopenharmony_ci var message = new proto.jspb.test.TestAllTypes(); 86ffe3c632Sopenharmony_ci var bytes = new Uint8Array(4); 87ffe3c632Sopenharmony_ci message.setOptionalBytes(bytes); 88ffe3c632Sopenharmony_ci assertEquals(jspb.debug.dump(message)['optionalBytes'], bytes); 89ffe3c632Sopenharmony_ci }); 90ffe3c632Sopenharmony_ci 91ffe3c632Sopenharmony_ci it('testExtensions', function() { 92ffe3c632Sopenharmony_ci if (COMPILED) { 93ffe3c632Sopenharmony_ci return; 94ffe3c632Sopenharmony_ci } 95ffe3c632Sopenharmony_ci var extension = new proto.jspb.test.IsExtension(); 96ffe3c632Sopenharmony_ci extension.setExt1('ext1field'); 97ffe3c632Sopenharmony_ci var extendable = new proto.jspb.test.HasExtensions(); 98ffe3c632Sopenharmony_ci extendable.setStr1('v1'); 99ffe3c632Sopenharmony_ci extendable.setStr2('v2'); 100ffe3c632Sopenharmony_ci extendable.setStr3('v3'); 101ffe3c632Sopenharmony_ci extendable.setExtension(proto.jspb.test.IsExtension.extField, extension); 102ffe3c632Sopenharmony_ci 103ffe3c632Sopenharmony_ci assertObjectEquals({ 104ffe3c632Sopenharmony_ci '$name': 'proto.jspb.test.HasExtensions', 105ffe3c632Sopenharmony_ci 'str1': 'v1', 106ffe3c632Sopenharmony_ci 'str2': 'v2', 107ffe3c632Sopenharmony_ci 'str3': 'v3', 108ffe3c632Sopenharmony_ci '$extensions': { 109ffe3c632Sopenharmony_ci 'extField': { 110ffe3c632Sopenharmony_ci '$name': 'proto.jspb.test.IsExtension', 111ffe3c632Sopenharmony_ci 'ext1': 'ext1field' 112ffe3c632Sopenharmony_ci }, 113ffe3c632Sopenharmony_ci 'repeatedSimpleList': [] 114ffe3c632Sopenharmony_ci } 115ffe3c632Sopenharmony_ci }, jspb.debug.dump(extendable)); 116ffe3c632Sopenharmony_ci }); 117ffe3c632Sopenharmony_ci 118ffe3c632Sopenharmony_ci it('testMapsBasicTypes', function() { 119ffe3c632Sopenharmony_ci if (COMPILED) { 120ffe3c632Sopenharmony_ci return; 121ffe3c632Sopenharmony_ci } 122ffe3c632Sopenharmony_ci 123ffe3c632Sopenharmony_ci var message = new proto.jspb.test.TestMapFieldsNoBinary(); 124ffe3c632Sopenharmony_ci message.getMapBoolStringMap().set(true, 'bool_string_value1'); 125ffe3c632Sopenharmony_ci message.getMapBoolStringMap().set(false, 'bool_string_value2'); 126ffe3c632Sopenharmony_ci message.getMapStringInt32Map().set('key', 111); 127ffe3c632Sopenharmony_ci 128ffe3c632Sopenharmony_ci assertObjectEquals({ 129ffe3c632Sopenharmony_ci '$name': 'proto.jspb.test.TestMapFieldsNoBinary', 130ffe3c632Sopenharmony_ci 'mapBoolStringMap': { 131ffe3c632Sopenharmony_ci true: 'bool_string_value1', 132ffe3c632Sopenharmony_ci false: 'bool_string_value2' 133ffe3c632Sopenharmony_ci }, 134ffe3c632Sopenharmony_ci 'mapInt32StringMap': {}, 135ffe3c632Sopenharmony_ci 'mapInt64StringMap': {}, 136ffe3c632Sopenharmony_ci 'mapStringBoolMap': {}, 137ffe3c632Sopenharmony_ci 'mapStringDoubleMap': {}, 138ffe3c632Sopenharmony_ci 'mapStringEnumMap': {}, 139ffe3c632Sopenharmony_ci 'mapStringInt32Map': { 140ffe3c632Sopenharmony_ci 'key': 111 141ffe3c632Sopenharmony_ci }, 142ffe3c632Sopenharmony_ci 'mapStringInt64Map': {}, 143ffe3c632Sopenharmony_ci 'mapStringMsgMap': {}, 144ffe3c632Sopenharmony_ci 'mapStringStringMap': {}, 145ffe3c632Sopenharmony_ci 'mapStringTestmapfieldsMap': {} 146ffe3c632Sopenharmony_ci }, jspb.debug.dump(message)); 147ffe3c632Sopenharmony_ci }); 148ffe3c632Sopenharmony_ci 149ffe3c632Sopenharmony_ci it('testMapsMessageValues', function() { 150ffe3c632Sopenharmony_ci if (COMPILED) { 151ffe3c632Sopenharmony_ci return; 152ffe3c632Sopenharmony_ci } 153ffe3c632Sopenharmony_ci 154ffe3c632Sopenharmony_ci var value1 = new proto.jspb.test.MapValueMessageNoBinary(); 155ffe3c632Sopenharmony_ci value1.setFoo(1111); 156ffe3c632Sopenharmony_ci var value2 = new proto.jspb.test.MapValueMessageNoBinary(); 157ffe3c632Sopenharmony_ci value2.setFoo(2222); 158ffe3c632Sopenharmony_ci 159ffe3c632Sopenharmony_ci var message = new proto.jspb.test.TestMapFieldsNoBinary(); 160ffe3c632Sopenharmony_ci message.getMapStringMsgMap().set('key1', value1); 161ffe3c632Sopenharmony_ci message.getMapStringMsgMap().set('key2', value2); 162ffe3c632Sopenharmony_ci 163ffe3c632Sopenharmony_ci assertObjectEquals({ 164ffe3c632Sopenharmony_ci '$name': 'proto.jspb.test.TestMapFieldsNoBinary', 165ffe3c632Sopenharmony_ci 'mapBoolStringMap': {}, 166ffe3c632Sopenharmony_ci 'mapInt32StringMap': {}, 167ffe3c632Sopenharmony_ci 'mapInt64StringMap': {}, 168ffe3c632Sopenharmony_ci 'mapStringBoolMap': {}, 169ffe3c632Sopenharmony_ci 'mapStringDoubleMap': {}, 170ffe3c632Sopenharmony_ci 'mapStringEnumMap': {}, 171ffe3c632Sopenharmony_ci 'mapStringInt32Map': {}, 172ffe3c632Sopenharmony_ci 'mapStringInt64Map': {}, 173ffe3c632Sopenharmony_ci 'mapStringMsgMap': { 174ffe3c632Sopenharmony_ci 'key1': { 175ffe3c632Sopenharmony_ci '$name': 'proto.jspb.test.MapValueMessageNoBinary', 176ffe3c632Sopenharmony_ci 'foo': 1111 177ffe3c632Sopenharmony_ci }, 178ffe3c632Sopenharmony_ci 'key2': { 179ffe3c632Sopenharmony_ci '$name': 'proto.jspb.test.MapValueMessageNoBinary', 180ffe3c632Sopenharmony_ci 'foo': 2222 181ffe3c632Sopenharmony_ci } 182ffe3c632Sopenharmony_ci }, 183ffe3c632Sopenharmony_ci 'mapStringStringMap': {}, 184ffe3c632Sopenharmony_ci 'mapStringTestmapfieldsMap': {} 185ffe3c632Sopenharmony_ci }, jspb.debug.dump(message)); 186ffe3c632Sopenharmony_ci }); 187ffe3c632Sopenharmony_ci 188ffe3c632Sopenharmony_ci}); 189