• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
31goog.setTestOnly();
32
33goog.require('goog.testing.asserts');
34
35// CommonJS-LoadFromFile: google-protobuf
36goog.require('jspb.debug');
37
38// CommonJS-LoadFromFile: test_pb
39goog.require('proto.jspb.test.HasExtensions');
40goog.require('proto.jspb.test.IsExtension');
41goog.require('proto.jspb.test.MapValueMessageNoBinary');
42goog.require('proto.jspb.test.Simple1');
43goog.require('proto.jspb.test.TestMapFieldsNoBinary');
44
45
46// CommonJS-LoadFromFile: testbinary_pb
47goog.require('proto.jspb.test.TestAllTypes');
48
49describe('debugTest', function() {
50  it('testSimple1', function() {
51    if (COMPILED) {
52      return;
53    }
54    var message = new proto.jspb.test.Simple1();
55    message.setAString('foo');
56    assertObjectEquals({
57      $name: 'proto.jspb.test.Simple1',
58      'aString': 'foo',
59      'aRepeatedStringList': []
60    }, jspb.debug.dump(message));
61
62    message.setABoolean(true);
63    message.setARepeatedStringList(['1', '2']);
64
65    assertObjectEquals({
66      $name: 'proto.jspb.test.Simple1',
67      'aString': 'foo',
68      'aRepeatedStringList': ['1', '2'],
69      'aBoolean': true
70    }, jspb.debug.dump(message));
71
72    message.clearAString();
73
74    assertObjectEquals({
75      $name: 'proto.jspb.test.Simple1',
76      'aRepeatedStringList': ['1', '2'],
77      'aBoolean': true
78    }, jspb.debug.dump(message));
79  });
80
81  it('testBytes', function() {
82    if (COMPILED || typeof Uint8Array == 'undefined') {
83      return;
84    }
85    var message = new proto.jspb.test.TestAllTypes();
86    var bytes = new Uint8Array(4);
87    message.setOptionalBytes(bytes);
88    assertEquals(jspb.debug.dump(message)['optionalBytes'], bytes);
89  });
90
91  it('testExtensions', function() {
92    if (COMPILED) {
93      return;
94    }
95    var extension = new proto.jspb.test.IsExtension();
96    extension.setExt1('ext1field');
97    var extendable = new proto.jspb.test.HasExtensions();
98    extendable.setStr1('v1');
99    extendable.setStr2('v2');
100    extendable.setStr3('v3');
101    extendable.setExtension(proto.jspb.test.IsExtension.extField, extension);
102
103    assertObjectEquals({
104      '$name': 'proto.jspb.test.HasExtensions',
105      'str1': 'v1',
106      'str2': 'v2',
107      'str3': 'v3',
108      '$extensions': {
109        'extField': {
110          '$name': 'proto.jspb.test.IsExtension',
111          'ext1': 'ext1field'
112        },
113        'repeatedSimpleList': []
114      }
115    }, jspb.debug.dump(extendable));
116  });
117
118  it('testMapsBasicTypes', function() {
119    if (COMPILED) {
120      return;
121    }
122
123    var message = new proto.jspb.test.TestMapFieldsNoBinary();
124    message.getMapBoolStringMap().set(true, 'bool_string_value1');
125    message.getMapBoolStringMap().set(false, 'bool_string_value2');
126    message.getMapStringInt32Map().set('key', 111);
127
128    assertObjectEquals({
129      '$name': 'proto.jspb.test.TestMapFieldsNoBinary',
130      'mapBoolStringMap': {
131        true: 'bool_string_value1',
132        false: 'bool_string_value2'
133      },
134      'mapInt32StringMap': {},
135      'mapInt64StringMap': {},
136      'mapStringBoolMap': {},
137      'mapStringDoubleMap': {},
138      'mapStringEnumMap': {},
139      'mapStringInt32Map': {
140        'key': 111
141      },
142      'mapStringInt64Map': {},
143      'mapStringMsgMap': {},
144      'mapStringStringMap': {},
145      'mapStringTestmapfieldsMap': {}
146    }, jspb.debug.dump(message));
147  });
148
149  it('testMapsMessageValues', function() {
150    if (COMPILED) {
151      return;
152    }
153
154    var value1 = new proto.jspb.test.MapValueMessageNoBinary();
155    value1.setFoo(1111);
156    var value2 = new proto.jspb.test.MapValueMessageNoBinary();
157    value2.setFoo(2222);
158
159    var message = new proto.jspb.test.TestMapFieldsNoBinary();
160    message.getMapStringMsgMap().set('key1', value1);
161    message.getMapStringMsgMap().set('key2', value2);
162
163    assertObjectEquals({
164      '$name': 'proto.jspb.test.TestMapFieldsNoBinary',
165      'mapBoolStringMap': {},
166      'mapInt32StringMap': {},
167      'mapInt64StringMap': {},
168      'mapStringBoolMap': {},
169      'mapStringDoubleMap': {},
170      'mapStringEnumMap': {},
171      'mapStringInt32Map': {},
172      'mapStringInt64Map': {},
173      'mapStringMsgMap': {
174        'key1': {
175          '$name': 'proto.jspb.test.MapValueMessageNoBinary',
176          'foo': 1111
177        },
178        'key2': {
179          '$name': 'proto.jspb.test.MapValueMessageNoBinary',
180          'foo': 2222
181        }
182      },
183      'mapStringStringMap': {},
184      'mapStringTestmapfieldsMap': {}
185    }, jspb.debug.dump(message));
186  });
187
188});
189