007ff5448db77afee468aaf82d37a58ed0a72dbe
[nit.git] / tests / test_binary_deserialization.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import test_deserialization
16 import binary::serialization
17 #alt1# import test_deserialization_serial
18
19 var entities = new TestEntities
20
21 var tests = entities.without_generics#alt1#
22 #alt1#var tests = entities.with_generics
23
24 var dir = "out/test_binary_deserialization"
25 if not dir.file_exists then dir.mkdir
26
27 var path = dir / "alt0"#alt1#
28 #alt1#var path = dir / "alt1"
29
30 var writer = new FileWriter.open(path)
31 var serializer = new BinarySerializer(writer)
32 for o in tests do
33 serializer.serialize o
34 end
35 writer.close
36
37 var reader = new FileReader.open(path)
38 var deserializer = new BinaryDeserializer(reader)
39 for o in tests do
40 var dst = deserializer.deserialize
41
42 assert dst != null
43 assert o.is_same_type(dst)
44
45 print "# Src:\n{o}"
46 print "# Dst:\n{dst}\n"
47 end
48 reader.close