murgatroid99 | f4cbf74 | 2015-06-05 13:50:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | 'use strict'; |
| 35 | |
| 36 | var assert = require('assert'); |
| 37 | |
| 38 | var common = require('../src/common.js'); |
| 39 | |
| 40 | var ProtoBuf = require('protobufjs'); |
| 41 | |
murgatroid99 | 9d5ae1c | 2015-06-05 13:58:25 -0700 | [diff] [blame] | 42 | var messages_proto = ProtoBuf.loadProtoFile( |
| 43 | __dirname + '/test_messages.proto').build(); |
murgatroid99 | f4cbf74 | 2015-06-05 13:50:04 -0700 | [diff] [blame] | 44 | |
| 45 | describe('Proto message serialize and deserialize', function() { |
| 46 | var longSerialize = common.serializeCls(messages_proto.LongValues); |
| 47 | var longDeserialize = common.deserializeCls(messages_proto.LongValues); |
| 48 | var pos_value = '314159265358979'; |
| 49 | var neg_value = '-27182818284590'; |
| 50 | it('should preserve positive int64 values', function() { |
| 51 | var serialized = longSerialize({int_64: pos_value}); |
| 52 | assert.strictEqual(longDeserialize(serialized).int_64.toString(), |
| 53 | pos_value); |
| 54 | }); |
| 55 | it('should preserve negative int64 values', function() { |
| 56 | var serialized = longSerialize({int_64: neg_value}); |
| 57 | assert.strictEqual(longDeserialize(serialized).int_64.toString(), |
| 58 | neg_value); |
| 59 | }); |
| 60 | it('should preserve uint64 values', function() { |
| 61 | var serialized = longSerialize({uint_64: pos_value}); |
| 62 | assert.strictEqual(longDeserialize(serialized).uint_64.toString(), |
| 63 | pos_value); |
| 64 | }); |
| 65 | it('should preserve positive sint64 values', function() { |
| 66 | var serialized = longSerialize({sint_64: pos_value}); |
| 67 | assert.strictEqual(longDeserialize(serialized).sint_64.toString(), |
| 68 | pos_value); |
| 69 | }); |
| 70 | it('should preserve negative sint64 values', function() { |
| 71 | var serialized = longSerialize({sint_64: neg_value}); |
| 72 | assert.strictEqual(longDeserialize(serialized).sint_64.toString(), |
| 73 | neg_value); |
| 74 | }); |
| 75 | it('should preserve fixed64 values', function() { |
| 76 | var serialized = longSerialize({fixed_64: pos_value}); |
| 77 | assert.strictEqual(longDeserialize(serialized).fixed_64.toString(), |
| 78 | pos_value); |
| 79 | }); |
| 80 | it('should preserve positive sfixed64 values', function() { |
| 81 | var serialized = longSerialize({sfixed_64: pos_value}); |
| 82 | assert.strictEqual(longDeserialize(serialized).sfixed_64.toString(), |
| 83 | pos_value); |
| 84 | }); |
| 85 | it('should preserve negative sfixed64 values', function() { |
| 86 | var serialized = longSerialize({sfixed_64: neg_value}); |
| 87 | assert.strictEqual(longDeserialize(serialized).sfixed_64.toString(), |
| 88 | neg_value); |
| 89 | }); |
| 90 | }); |