Mark Erickson | e1abc8b | 2016-06-07 16:24:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | library thrift.test.serializer.serializer_test; |
| 21 | |
| 22 | import 'package:test/test.dart'; |
| 23 | import 'package:thrift/thrift.dart'; |
| 24 | import 'serializer_test_data.dart'; |
| 25 | |
| 26 | void main() { |
| 27 | var serializer = () { |
| 28 | TDeserializer deserializer; |
| 29 | TSerializer serializer; |
| 30 | TestTObject testTObject; |
| 31 | |
| 32 | setUp(() { |
| 33 | serializer = new TSerializer(); |
| 34 | deserializer = new TDeserializer(); |
| 35 | |
| 36 | testTObject = new TestTObject(); |
| 37 | testTObject.b = true; |
| 38 | testTObject.s = "TEST"; |
| 39 | testTObject.d = 15.25; |
| 40 | testTObject.i = 10; |
| 41 | |
| 42 | var testList = new List<String>(); |
| 43 | testList.add("TEST 1"); |
| 44 | testList.add("TEST 2"); |
| 45 | |
| 46 | testTObject.l = testList; |
| 47 | }); |
| 48 | |
| 49 | assertNewObjectEqualsTObject(TestTObject newObject) { |
| 50 | expect(newObject.l, equals(testTObject.l)); |
| 51 | expect(newObject.b, equals(testTObject.b)); |
| 52 | expect(newObject.i, equals(testTObject.i)); |
| 53 | expect(newObject.d, equals(testTObject.d)); |
| 54 | expect(newObject.s, equals(testTObject.s)); |
| 55 | } |
| 56 | |
| 57 | runWriteStringTest() { |
| 58 | var s = serializer.writeString(testTObject); |
| 59 | |
| 60 | var newObject = new TestTObject(); |
| 61 | deserializer.readString(newObject, s); |
| 62 | |
| 63 | assertNewObjectEqualsTObject(newObject); |
| 64 | }; |
| 65 | |
| 66 | runWriteTest() { |
| 67 | var s = serializer.write(testTObject); |
| 68 | |
| 69 | var newObject = new TestTObject(); |
| 70 | deserializer.read(newObject, s); |
| 71 | |
| 72 | assertNewObjectEqualsTObject(newObject); |
| 73 | }; |
| 74 | |
| 75 | test('JSON Protocol String', () { |
| 76 | serializer.protocol = new TJsonProtocol(serializer.transport); |
| 77 | deserializer.protocol = new TJsonProtocol(deserializer.transport); |
| 78 | |
| 79 | runWriteStringTest(); |
| 80 | }); |
| 81 | |
| 82 | test('JSON Protocol', () { |
| 83 | serializer.protocol = new TJsonProtocol(serializer.transport); |
| 84 | deserializer.protocol = new TJsonProtocol(deserializer.transport); |
| 85 | |
| 86 | runWriteTest(); |
| 87 | }); |
| 88 | |
| 89 | test('Binary Protocol String', () { |
| 90 | serializer.protocol = new TBinaryProtocol(serializer.transport); |
| 91 | deserializer.protocol = new TBinaryProtocol(deserializer.transport); |
| 92 | |
| 93 | runWriteStringTest(); |
| 94 | }); |
| 95 | |
| 96 | test('Binary Protocol', () { |
| 97 | serializer.protocol = new TBinaryProtocol(serializer.transport); |
| 98 | deserializer.protocol = new TBinaryProtocol(deserializer.transport); |
| 99 | |
| 100 | runWriteTest(); |
| 101 | }); |
| 102 | |
| 103 | test('Compact Protocol String', () { |
| 104 | serializer.protocol = new TCompactProtocol(serializer.transport); |
| 105 | deserializer.protocol = new TCompactProtocol(deserializer.transport); |
| 106 | |
| 107 | runWriteStringTest(); |
| 108 | }); |
| 109 | |
| 110 | test('Compact Protocol', () { |
| 111 | serializer.protocol = new TCompactProtocol(serializer.transport); |
| 112 | deserializer.protocol = new TCompactProtocol(deserializer.transport); |
| 113 | |
| 114 | runWriteTest(); |
| 115 | }); |
| 116 | }; |
| 117 | |
| 118 | group('Serializer', serializer); |
| 119 | } |