blob: 89883cb7c02c41cf29df004d5ff11c0a6e30958d [file] [log] [blame]
Mark Ericksone1abc8b2016-06-07 16:24:23 -05001/*
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
20library thrift.test.serializer.serializer_test;
21
22import 'package:test/test.dart';
23import 'package:thrift/thrift.dart';
24import 'serializer_test_data.dart';
25
26void main() {
27 var serializer = () {
28 TDeserializer deserializer;
29 TSerializer serializer;
30 TestTObject testTObject;
31
32 setUp(() {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020033 serializer = TSerializer();
34 deserializer = TDeserializer();
35
36 testTObject = TestTObject();
Mark Ericksone1abc8b2016-06-07 16:24:23 -050037 testTObject.b = true;
38 testTObject.s = "TEST";
39 testTObject.d = 15.25;
40 testTObject.i = 10;
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020041
42 var testList = List<String>();
Mark Ericksone1abc8b2016-06-07 16:24:23 -050043 testList.add("TEST 1");
44 testList.add("TEST 2");
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020045
Mark Ericksone1abc8b2016-06-07 16:24:23 -050046 testTObject.l = testList;
47 });
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020048
Mark Ericksone1abc8b2016-06-07 16:24:23 -050049 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 }
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020056
Mark Ericksone1abc8b2016-06-07 16:24:23 -050057 runWriteStringTest() {
58 var s = serializer.writeString(testTObject);
59
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020060 var newObject = TestTObject();
Mark Ericksone1abc8b2016-06-07 16:24:23 -050061 deserializer.readString(newObject, s);
62
63 assertNewObjectEqualsTObject(newObject);
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020064 }
Mark Ericksone1abc8b2016-06-07 16:24:23 -050065
66 runWriteTest() {
67 var s = serializer.write(testTObject);
68
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020069 var newObject = TestTObject();
Mark Ericksone1abc8b2016-06-07 16:24:23 -050070 deserializer.read(newObject, s);
71
72 assertNewObjectEqualsTObject(newObject);
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020073 }
Mark Ericksone1abc8b2016-06-07 16:24:23 -050074
75 test('JSON Protocol String', () {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020076 serializer.protocol = TJsonProtocol(serializer.transport);
77 deserializer.protocol = TJsonProtocol(deserializer.transport);
78
Mark Ericksone1abc8b2016-06-07 16:24:23 -050079 runWriteStringTest();
80 });
81
82 test('JSON Protocol', () {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020083 serializer.protocol = TJsonProtocol(serializer.transport);
84 deserializer.protocol = TJsonProtocol(deserializer.transport);
Mark Ericksone1abc8b2016-06-07 16:24:23 -050085
86 runWriteTest();
87 });
88
89 test('Binary Protocol String', () {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020090 serializer.protocol = TBinaryProtocol(serializer.transport);
91 deserializer.protocol = TBinaryProtocol(deserializer.transport);
Mark Ericksone1abc8b2016-06-07 16:24:23 -050092
93 runWriteStringTest();
94 });
95
96 test('Binary Protocol', () {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +020097 serializer.protocol = TBinaryProtocol(serializer.transport);
98 deserializer.protocol = TBinaryProtocol(deserializer.transport);
Mark Ericksone1abc8b2016-06-07 16:24:23 -050099
100 runWriteTest();
101 });
102
103 test('Compact Protocol String', () {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +0200104 serializer.protocol = TCompactProtocol(serializer.transport);
105 deserializer.protocol = TCompactProtocol(deserializer.transport);
Mark Ericksone1abc8b2016-06-07 16:24:23 -0500106
107 runWriteStringTest();
108 });
109
110 test('Compact Protocol', () {
aaronstgeorge-wf1ab156a2020-10-01 17:28:28 +0200111 serializer.protocol = TCompactProtocol(serializer.transport);
112 deserializer.protocol = TCompactProtocol(deserializer.transport);
Mark Ericksone1abc8b2016-06-07 16:24:23 -0500113
114 runWriteTest();
115 });
116 };
117
118 group('Serializer', serializer);
119}