[13368] | 1 | #region License Information
|
---|
[6846] | 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6846] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections;
|
---|
| 24 | using System.Collections.Generic;
|
---|
[13409] | 25 | using System.Diagnostics;
|
---|
[6846] | 26 | using System.Drawing;
|
---|
[11352] | 27 | using System.Globalization;
|
---|
[6846] | 28 | using System.IO;
|
---|
| 29 | using System.Linq;
|
---|
| 30 | using System.Reflection;
|
---|
| 31 | using System.Text;
|
---|
| 32 | using System.Threading.Tasks;
|
---|
| 33 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
[14739] | 34 | using HeuristicLab.Core;
|
---|
[13409] | 35 | using HeuristicLab.Data;
|
---|
[14594] | 36 | using HeuristicLab.Persistence;
|
---|
[6846] | 37 | using HeuristicLab.Persistence.Auxiliary;
|
---|
| 38 | using HeuristicLab.Persistence.Core;
|
---|
| 39 | using HeuristicLab.Persistence.Default.DebugString;
|
---|
| 40 | using HeuristicLab.Persistence.Default.Xml;
|
---|
[13386] | 41 | using HeuristicLab.Persistence.Tests;
|
---|
[14594] | 42 | using HeuristicLab.Problems.TestFunctions;
|
---|
[9764] | 43 | using HeuristicLab.Tests;
|
---|
[6846] | 44 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 45 |
|
---|
[13386] | 46 | namespace HeuristicLab.PersistenceNew.Tests {
|
---|
[13409] | 47 | public static class EnumerableTimeSpanExtensions {
|
---|
| 48 | public static TimeSpan Average(this IEnumerable<TimeSpan> span) {
|
---|
| 49 | var avg = (long)Math.Round(span.Select(x => x.Ticks).Average());
|
---|
| 50 | return new TimeSpan(avg);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[13386] | 54 | #region Test Classes
|
---|
[14711] | 55 | [StorableType("7D9672BD-703D-42BB-9080-9929885D4580")]
|
---|
[6846] | 56 | public class NumberTest {
|
---|
| 57 | [Storable]
|
---|
| 58 | private bool _bool = true;
|
---|
| 59 | [Storable]
|
---|
| 60 | private byte _byte = 0xFF;
|
---|
| 61 | [Storable]
|
---|
| 62 | private sbyte _sbyte = 0xF;
|
---|
| 63 | [Storable]
|
---|
| 64 | private short _short = -123;
|
---|
| 65 | [Storable]
|
---|
| 66 | private ushort _ushort = 123;
|
---|
| 67 | [Storable]
|
---|
| 68 | private int _int = -123;
|
---|
| 69 | [Storable]
|
---|
| 70 | private uint _uint = 123;
|
---|
| 71 | [Storable]
|
---|
| 72 | private long _long = 123456;
|
---|
| 73 | [Storable]
|
---|
| 74 | private ulong _ulong = 123456;
|
---|
| 75 | public override bool Equals(object obj) {
|
---|
| 76 | NumberTest nt = obj as NumberTest;
|
---|
| 77 | if (nt == null)
|
---|
| 78 | throw new NotSupportedException();
|
---|
| 79 | return
|
---|
| 80 | nt._bool == _bool &&
|
---|
| 81 | nt._byte == _byte &&
|
---|
| 82 | nt._sbyte == _sbyte &&
|
---|
| 83 | nt._short == _short &&
|
---|
| 84 | nt._ushort == _ushort &&
|
---|
| 85 | nt._int == _int &&
|
---|
| 86 | nt._uint == _uint &&
|
---|
| 87 | nt._long == _long &&
|
---|
| 88 | nt._ulong == _ulong;
|
---|
| 89 | }
|
---|
| 90 | public override int GetHashCode() {
|
---|
| 91 | return
|
---|
| 92 | _bool.GetHashCode() ^
|
---|
| 93 | _byte.GetHashCode() ^
|
---|
| 94 | _sbyte.GetHashCode() ^
|
---|
| 95 | _short.GetHashCode() ^
|
---|
| 96 | _short.GetHashCode() ^
|
---|
| 97 | _int.GetHashCode() ^
|
---|
| 98 | _uint.GetHashCode() ^
|
---|
| 99 | _long.GetHashCode() ^
|
---|
| 100 | _ulong.GetHashCode();
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[14711] | 104 | [StorableType("EEB19599-D5AC-48ED-A56B-CF213DFAF2E4")]
|
---|
[6846] | 105 | public class NonDefaultConstructorClass {
|
---|
| 106 | [Storable]
|
---|
| 107 | int value;
|
---|
| 108 | public NonDefaultConstructorClass(int value) {
|
---|
| 109 | this.value = value;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[14711] | 113 | [StorableType("EE43FE7A-6D07-4D52-9338-C21B3485F82A")]
|
---|
[6846] | 114 | public class IntWrapper {
|
---|
| 115 |
|
---|
| 116 | [Storable]
|
---|
| 117 | public int Value;
|
---|
| 118 |
|
---|
| 119 | private IntWrapper() { }
|
---|
| 120 |
|
---|
| 121 | public IntWrapper(int value) {
|
---|
| 122 | this.Value = value;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | public override bool Equals(object obj) {
|
---|
| 126 | if (obj as IntWrapper == null)
|
---|
| 127 | return false;
|
---|
| 128 | return Value.Equals(((IntWrapper)obj).Value);
|
---|
| 129 | }
|
---|
| 130 | public override int GetHashCode() {
|
---|
| 131 | return Value.GetHashCode();
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[14711] | 136 | [StorableType("00A8E48E-8E8A-443C-A327-9F6ACCBE7E80")]
|
---|
[6846] | 137 | public class PrimitivesTest : NumberTest {
|
---|
| 138 | [Storable]
|
---|
| 139 | private char c = 'e';
|
---|
| 140 | [Storable]
|
---|
| 141 | private long[,] _long_array =
|
---|
| 142 | new long[,] { { 123, 456, }, { 789, 123 } };
|
---|
| 143 | [Storable]
|
---|
| 144 | public List<int> list = new List<int> { 1, 2, 3, 4, 5 };
|
---|
| 145 | [Storable]
|
---|
| 146 | private object o = new object();
|
---|
| 147 | public override bool Equals(object obj) {
|
---|
| 148 | PrimitivesTest pt = obj as PrimitivesTest;
|
---|
| 149 | if (pt == null)
|
---|
| 150 | throw new NotSupportedException();
|
---|
| 151 | return base.Equals(obj) &&
|
---|
| 152 | c == pt.c &&
|
---|
| 153 | _long_array == pt._long_array &&
|
---|
| 154 | list == pt.list &&
|
---|
| 155 | o == pt.o;
|
---|
| 156 | }
|
---|
| 157 | public override int GetHashCode() {
|
---|
| 158 | return base.GetHashCode() ^
|
---|
| 159 | c.GetHashCode() ^
|
---|
| 160 | _long_array.GetHashCode() ^
|
---|
| 161 | list.GetHashCode() ^
|
---|
| 162 | o.GetHashCode();
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[14928] | 166 | [StorableType("c15e3ac3-2681-48a1-9171-d97321cd60bb")]
|
---|
[13407] | 167 | public enum TestEnum { va1, va2, va3, va8 };
|
---|
[6846] | 168 |
|
---|
[14711] | 169 | [StorableType("26BA37F6-926D-4665-A10A-1F39E1CF6468")]
|
---|
[6846] | 170 | public class RootBase {
|
---|
| 171 | [Storable]
|
---|
| 172 | private string baseString = " Serial ";
|
---|
| 173 | [Storable]
|
---|
| 174 | public TestEnum myEnum = TestEnum.va3;
|
---|
| 175 | public override bool Equals(object obj) {
|
---|
| 176 | RootBase rb = obj as RootBase;
|
---|
| 177 | if (rb == null)
|
---|
| 178 | throw new NotSupportedException();
|
---|
| 179 | return baseString == rb.baseString &&
|
---|
| 180 | myEnum == rb.myEnum;
|
---|
| 181 | }
|
---|
| 182 | public override int GetHashCode() {
|
---|
| 183 | return baseString.GetHashCode() ^
|
---|
| 184 | myEnum.GetHashCode();
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[14711] | 188 | [StorableType("F6BCB436-B5F2-40F6-8E2F-7A018CD1CBA0")]
|
---|
[6846] | 189 | public class Root : RootBase {
|
---|
| 190 | [Storable]
|
---|
| 191 | public Stack<int> intStack = new Stack<int>();
|
---|
| 192 | [Storable]
|
---|
| 193 | public int[] i = new[] { 3, 4, 5, 6 };
|
---|
| 194 | [Storable(Name = "Test String")]
|
---|
| 195 | public string s;
|
---|
| 196 | [Storable]
|
---|
| 197 | public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
|
---|
| 198 | [Storable]
|
---|
| 199 | public List<int> intList = new List<int>(new[] { 321, 312, 321 });
|
---|
| 200 | [Storable]
|
---|
| 201 | public Custom c;
|
---|
| 202 | [Storable]
|
---|
| 203 | public List<Root> selfReferences;
|
---|
| 204 | [Storable]
|
---|
| 205 | public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
|
---|
| 206 | [Storable]
|
---|
| 207 | public bool boolean = true;
|
---|
| 208 | [Storable]
|
---|
| 209 | public DateTime dateTime;
|
---|
| 210 | [Storable]
|
---|
| 211 | public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("Serial", 123);
|
---|
| 212 | [Storable]
|
---|
| 213 | public Dictionary<string, int> dict = new Dictionary<string, int>();
|
---|
| 214 | [Storable(DefaultValue = "default")]
|
---|
| 215 | public string uninitialized;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[14928] | 218 | [StorableType("a6bd45c2-bf18-47d7-9f66-c130222f2f00")]
|
---|
[6846] | 219 | public enum SimpleEnum { one, two, three }
|
---|
[14928] | 220 | [StorableType("b5c8285e-5c1b-457e-a5a3-e25eb588c283")]
|
---|
[6846] | 221 | public enum ComplexEnum { one = 1, two = 2, three = 3 }
|
---|
| 222 | [FlagsAttribute]
|
---|
[14928] | 223 | [StorableType("c2ee7205-0a3a-443a-87d6-68568c4f4153")]
|
---|
[6846] | 224 | public enum TrickyEnum { zero = 0, one = 1, two = 2 }
|
---|
| 225 |
|
---|
[14711] | 226 | [StorableType("2F6326ED-023A-415F-B5C7-9F9241940D05")]
|
---|
[6846] | 227 | public class EnumTest {
|
---|
| 228 | [Storable]
|
---|
| 229 | public SimpleEnum simpleEnum = SimpleEnum.one;
|
---|
| 230 | [Storable]
|
---|
| 231 | public ComplexEnum complexEnum = (ComplexEnum)2;
|
---|
| 232 | [Storable]
|
---|
| 233 | public TrickyEnum trickyEnum = (TrickyEnum)15;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[14711] | 236 | [StorableType("92365E2A-1184-4280-B763-4853C7ADF3E3")]
|
---|
[6846] | 237 | public class Custom {
|
---|
| 238 | [Storable]
|
---|
| 239 | public int i;
|
---|
| 240 | [Storable]
|
---|
| 241 | public Root r;
|
---|
| 242 | [Storable]
|
---|
| 243 | public string name = "<![CDATA[<![CDATA[Serial]]>]]>";
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[14711] | 246 | [StorableType("7CF19EBC-1EC4-4FBE-BCA9-DA48E3CFE30D")]
|
---|
[6846] | 247 | public class Manager {
|
---|
| 248 |
|
---|
| 249 | public DateTime lastLoadTime;
|
---|
| 250 | [Storable]
|
---|
| 251 | private DateTime lastLoadTimePersistence {
|
---|
| 252 | get { return lastLoadTime; }
|
---|
| 253 | set { lastLoadTime = DateTime.Now; }
|
---|
| 254 | }
|
---|
| 255 | [Storable]
|
---|
| 256 | public double? dbl;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[14711] | 259 | [StorableType("9092C705-F5E9-4BA9-9750-4357DB29AABF")]
|
---|
[6846] | 260 | public class C {
|
---|
| 261 | [Storable]
|
---|
| 262 | public C[][] allCs;
|
---|
| 263 | [Storable]
|
---|
| 264 | public KeyValuePair<List<C>, C> kvpList;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | public class NonSerializable {
|
---|
| 268 | int x = 0;
|
---|
| 269 | public override bool Equals(object obj) {
|
---|
| 270 | NonSerializable ns = obj as NonSerializable;
|
---|
| 271 | if (ns == null)
|
---|
| 272 | throw new NotSupportedException();
|
---|
| 273 | return ns.x == x;
|
---|
| 274 | }
|
---|
| 275 | public override int GetHashCode() {
|
---|
| 276 | return x.GetHashCode();
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
[14711] | 280 | [StorableType("FD953B0A-BDE6-41E6-91A8-CA3D90C91CDB")]
|
---|
[13409] | 281 | public class SimpleClass {
|
---|
[14537] | 282 | [Storable]
|
---|
[13409] | 283 | public double x { get; set; }
|
---|
[14537] | 284 | [Storable]
|
---|
[13409] | 285 | public int y { get; set; }
|
---|
| 286 | }
|
---|
[13386] | 287 | #endregion
|
---|
[6846] | 288 |
|
---|
| 289 | [TestClass]
|
---|
[14928] | 290 | [StorableType("6324d1f6-a82b-4914-937a-21846c4af9e6")]
|
---|
[13386] | 291 | public class UseCasesPersistenceNew {
|
---|
| 292 | #region Helpers
|
---|
[6846] | 293 | private string tempFile;
|
---|
[15857] | 294 | private static Dictionary<Guid, Type> guid2Type;
|
---|
| 295 | private static Dictionary<Type, Guid> type2Guid;
|
---|
| 296 | private static Dictionary<Type, Persistence.TypeInfo> typeInfos;
|
---|
| 297 | private static PropertyInfo guidPropertyInfo = typeof(StorableTypeAttribute).GetProperty("Guid");
|
---|
[6846] | 298 |
|
---|
[15857] | 299 |
|
---|
[13386] | 300 | [ClassInitialize]
|
---|
| 301 | public static void Initialize(TestContext testContext) {
|
---|
| 302 | ConfigurationService.Instance.Reset();
|
---|
[15857] | 303 |
|
---|
| 304 | var guid2TypeFieldInfo = typeof(StaticCache).GetField("guid2Type", BindingFlags.NonPublic | BindingFlags.Instance);
|
---|
| 305 | var type2GuidFieldInfo = typeof(StaticCache).GetField("type2Guid", BindingFlags.NonPublic | BindingFlags.Instance);
|
---|
| 306 | var typeInfosFieldInfo = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance);
|
---|
| 307 |
|
---|
| 308 | guid2Type = (Dictionary<Guid, Type>)guid2TypeFieldInfo.GetValue(Mapper.StaticCache);
|
---|
| 309 | type2Guid = (Dictionary<Type, Guid>)type2GuidFieldInfo.GetValue(Mapper.StaticCache);
|
---|
| 310 | typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosFieldInfo.GetValue(Mapper.StaticCache);
|
---|
[13386] | 311 | }
|
---|
| 312 |
|
---|
[6846] | 313 | [TestInitialize()]
|
---|
| 314 | public void CreateTempFile() {
|
---|
| 315 | tempFile = Path.GetTempFileName();
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | [TestCleanup()]
|
---|
| 319 | public void ClearTempFile() {
|
---|
| 320 | StreamReader reader = new StreamReader(tempFile);
|
---|
| 321 | string s = reader.ReadToEnd();
|
---|
| 322 | reader.Close();
|
---|
| 323 | File.Delete(tempFile);
|
---|
| 324 | }
|
---|
[15857] | 325 |
|
---|
| 326 | public static void RegisterType(Guid guid, Type type) {
|
---|
| 327 | Mapper.StaticCache.RegisterType(guid, type);
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | public static void DeregisterType(Type type) {
|
---|
| 331 | var typeInfo = GetTypeInfo(type);
|
---|
| 332 | type2Guid.Remove(guid2Type[typeInfo.StorableTypeAttribute.Guid]);
|
---|
| 333 | guid2Type.Remove(typeInfo.StorableTypeAttribute.Guid);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | public static Persistence.TypeInfo GetTypeInfo(Type type) {
|
---|
| 337 | return Mapper.StaticCache.GetTypeInfo(type);
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | public static void RemoveTypeInfo(Type type) {
|
---|
| 341 | typeInfos.Remove(typeof(ConversionA));
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | public static Guid GetTypeGuid(Type type) {
|
---|
| 345 | var typeInfo = GetTypeInfo(type);
|
---|
| 346 | return typeInfo.StorableTypeAttribute.Guid;
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | public static void SetTypeGuid(Type type, Guid guid) {
|
---|
| 350 | var typeInfo = GetTypeInfo(type);
|
---|
| 351 | guidPropertyInfo.SetValue(typeInfo.StorableTypeAttribute, guid);
|
---|
| 352 | }
|
---|
[13386] | 353 | #endregion
|
---|
[6846] | 354 |
|
---|
[13409] | 355 | #region Persistence 4.0 Profiling Helpers
|
---|
[14928] | 356 | [StorableType("f90de8e3-e7d1-43b2-a8f0-6689ec922e87")]
|
---|
[13409] | 357 | public class PerformanceData {
|
---|
| 358 | public TimeSpan OldSerializingTime { get; set; }
|
---|
| 359 | public TimeSpan NewSerializingTime { get; set; }
|
---|
| 360 | public TimeSpan OldDeserializingTime { get; set; }
|
---|
| 361 | public TimeSpan NewDeserializingTime { get; set; }
|
---|
| 362 | public long OldFileSize { get; set; }
|
---|
| 363 | public long NewFileSize { get; set; }
|
---|
| 364 | public long OldSerializingMemoryConsumed { get; set; }
|
---|
| 365 | public long NewSerializingMemoryConsumed { get; set; }
|
---|
| 366 | public long OldDeserializingMemoryConsumed { get; set; }
|
---|
| 367 | public long NewDeserializingMemoryConsumed { get; set; }
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | private void SerializeNew(object o) {
|
---|
| 371 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 372 | serializer.Serialize(o, tempFile);
|
---|
| 373 | }
|
---|
| 374 | private void SerializeOld(object o) {
|
---|
| 375 | XmlGenerator.Serialize(o, tempFile);
|
---|
| 376 | }
|
---|
| 377 | private object DeserializeNew() {
|
---|
| 378 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 379 | return serializer.Deserialize(tempFile);
|
---|
| 380 | }
|
---|
| 381 | private object DeserialiezOld() {
|
---|
| 382 | return XmlParser.Deserialize(tempFile);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | private void CollectGarbage() {
|
---|
| 386 | GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
|
---|
| 387 | GC.WaitForPendingFinalizers();
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | public PerformanceData ProfileSingleRun(Func<object> GenerateDataFunc) {
|
---|
| 391 | PerformanceData performanceData = new PerformanceData();
|
---|
| 392 | Stopwatch sw = new Stopwatch();
|
---|
| 393 | object data = GenerateDataFunc();
|
---|
| 394 | object result = null;
|
---|
| 395 | long startMem, endMem;
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | //old file format serializing
|
---|
| 399 | CollectGarbage();
|
---|
| 400 | startMem = GC.GetTotalMemory(false);
|
---|
| 401 | sw.Start();
|
---|
| 402 | SerializeOld(data);
|
---|
| 403 | sw.Stop();
|
---|
| 404 | endMem = GC.GetTotalMemory(false);
|
---|
| 405 | performanceData.OldSerializingTime = sw.Elapsed;
|
---|
| 406 | performanceData.OldFileSize = new FileInfo(tempFile).Length;
|
---|
| 407 | performanceData.OldSerializingMemoryConsumed = endMem - startMem;
|
---|
| 408 | sw.Reset();
|
---|
| 409 |
|
---|
| 410 |
|
---|
| 411 | //old file format deserializing
|
---|
| 412 | CollectGarbage();
|
---|
| 413 | startMem = GC.GetTotalMemory(false);
|
---|
| 414 | sw.Start();
|
---|
| 415 | result = DeserialiezOld();
|
---|
| 416 | sw.Stop();
|
---|
| 417 | endMem = GC.GetTotalMemory(false);
|
---|
| 418 | performanceData.OldDeserializingTime = sw.Elapsed;
|
---|
| 419 | performanceData.OldDeserializingMemoryConsumed = endMem - startMem;
|
---|
| 420 | sw.Reset();
|
---|
| 421 |
|
---|
| 422 |
|
---|
| 423 | //new file format serializing
|
---|
| 424 | CollectGarbage();
|
---|
| 425 | startMem = GC.GetTotalMemory(false);
|
---|
| 426 | sw.Start();
|
---|
| 427 | SerializeNew(data);
|
---|
| 428 | sw.Stop();
|
---|
| 429 | endMem = GC.GetTotalMemory(false);
|
---|
| 430 | performanceData.NewSerializingTime = sw.Elapsed;
|
---|
| 431 | performanceData.NewSerializingMemoryConsumed = endMem - startMem;
|
---|
| 432 | performanceData.NewFileSize = new FileInfo(tempFile).Length;
|
---|
| 433 | sw.Reset();
|
---|
| 434 |
|
---|
| 435 |
|
---|
| 436 | //new file format deserializing
|
---|
| 437 | CollectGarbage();
|
---|
| 438 | startMem = GC.GetTotalMemory(false);
|
---|
| 439 | sw.Start();
|
---|
| 440 | result = DeserializeNew();
|
---|
| 441 | sw.Stop();
|
---|
| 442 | endMem = GC.GetTotalMemory(false);
|
---|
| 443 | performanceData.NewDeserializingTime = sw.Elapsed;
|
---|
| 444 | performanceData.NewDeserializingMemoryConsumed = endMem - startMem;
|
---|
| 445 | sw.Reset();
|
---|
| 446 |
|
---|
| 447 | return performanceData;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
[15529] | 450 | public string Profile(Func<object> GenerateDataFunc, string filename = null) {
|
---|
[14714] | 451 | int nrOfRepetitions = 30;
|
---|
[13409] | 452 | StringBuilder report = new StringBuilder();
|
---|
| 453 | List<PerformanceData> dataList = new List<PerformanceData>();
|
---|
| 454 |
|
---|
| 455 | for (int i = 0; i < nrOfRepetitions; i++) {
|
---|
| 456 | dataList.Add(ProfileSingleRun(GenerateDataFunc));
|
---|
| 457 | }
|
---|
| 458 |
|
---|
[15529] | 459 | //report.Append("Performance Report for " + GenerateDataFunc.Method.Name + ": " + Environment.NewLine);
|
---|
[13409] | 460 | report.Append(Environment.NewLine);
|
---|
[15529] | 461 | report.AppendFormat("Avg. old vs. new time for serializing a file; {3};{0};{1};{2}",
|
---|
[13409] | 462 | dataList.Select(x => x.OldSerializingTime).Average(),
|
---|
| 463 | dataList.Select(x => x.NewSerializingTime).Average(),
|
---|
| 464 | dataList.Select(x => x.OldSerializingTime.TotalMilliseconds).Average() / dataList.Select(x => x.NewSerializingTime.TotalMilliseconds).Average()
|
---|
[15529] | 465 | , filename);
|
---|
[13409] | 466 | report.Append(Environment.NewLine);
|
---|
[15529] | 467 | report.AppendFormat("Avg. old vs. new time for deserializing a file; {3};{0};{1};{2}",
|
---|
[13409] | 468 | dataList.Select(x => x.OldDeserializingTime).Average(),
|
---|
| 469 | dataList.Select(x => x.NewDeserializingTime).Average(),
|
---|
| 470 | dataList.Select(x => x.OldDeserializingTime.TotalMilliseconds).Average() / dataList.Select(x => x.NewDeserializingTime.TotalMilliseconds).Average()
|
---|
[15529] | 471 | , filename);
|
---|
[13409] | 472 | report.Append(Environment.NewLine);
|
---|
[15529] | 473 | report.AppendFormat("Avg. old vs. new file size (in bytes); {3};{0};{1};{2}",
|
---|
[13409] | 474 | dataList.Select(x => x.OldFileSize).Average(),
|
---|
| 475 | dataList.Select(x => x.NewFileSize).Average(),
|
---|
| 476 | dataList.Select(x => x.OldFileSize).Average() / dataList.Select(x => x.NewFileSize).Average()
|
---|
[15529] | 477 | , filename);
|
---|
[13409] | 478 | report.Append(Environment.NewLine);
|
---|
[15529] | 479 | report.AppendFormat("Avg. old vs. new memory consumption for serializing a file (in bytes); {3};{0};{1};{2}",
|
---|
[13409] | 480 | dataList.Select(x => x.OldSerializingMemoryConsumed).Average(),
|
---|
| 481 | dataList.Select(x => x.NewSerializingMemoryConsumed).Average(),
|
---|
| 482 | dataList.Select(x => x.OldSerializingMemoryConsumed).Average() / dataList.Select(x => x.NewSerializingMemoryConsumed).Average()
|
---|
[15529] | 483 | , filename);
|
---|
[13409] | 484 | report.Append(Environment.NewLine);
|
---|
[15529] | 485 | report.AppendFormat("Avg. old vs. new memory consumption for deserializing a file (in bytes); {3};{0};{1};{2}",
|
---|
[13409] | 486 | dataList.Select(x => x.OldDeserializingMemoryConsumed).Average(),
|
---|
| 487 | dataList.Select(x => x.NewDeserializingMemoryConsumed).Average(),
|
---|
| 488 | dataList.Select(x => x.OldDeserializingMemoryConsumed).Average() / dataList.Select(x => x.NewDeserializingMemoryConsumed).Average()
|
---|
[15529] | 489 | , filename);
|
---|
[13409] | 490 | report.Append(Environment.NewLine);
|
---|
| 491 |
|
---|
| 492 |
|
---|
| 493 | return report.ToString();
|
---|
| 494 | }
|
---|
| 495 | #endregion
|
---|
| 496 |
|
---|
[15857] | 497 | #region Persistence 4.0 Test methods
|
---|
[6846] | 498 | [TestMethod]
|
---|
[15857] | 499 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 500 | [TestProperty("Time", "short")]
|
---|
[13386] | 501 | public void TestBool() {
|
---|
[13409] | 502 | var test = new Func<object>(() => { return true; });
|
---|
[13386] | 503 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13409] | 504 | serializer.Serialize(test(), tempFile);
|
---|
[13386] | 505 | object o = serializer.Deserialize(tempFile);
|
---|
| 506 | bool result = (bool)o;
|
---|
[13409] | 507 | Assert.AreEqual(test(), result);
|
---|
| 508 |
|
---|
| 509 | string msg = Profile(test);
|
---|
| 510 | Console.WriteLine(msg);
|
---|
[6846] | 511 | }
|
---|
| 512 |
|
---|
| 513 | [TestMethod]
|
---|
[15857] | 514 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 515 | [TestProperty("Time", "short")]
|
---|
[13386] | 516 | public void TestInt() {
|
---|
[13409] | 517 | var test = new Func<object>(() => { return (int)42; });
|
---|
[13386] | 518 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13409] | 519 | serializer.Serialize(test(), tempFile);
|
---|
[13386] | 520 | object o = serializer.Deserialize(tempFile);
|
---|
| 521 | int result = (int)o;
|
---|
[13409] | 522 | Assert.AreEqual(test(), result);
|
---|
| 523 |
|
---|
| 524 | string msg = Profile(test);
|
---|
| 525 | Console.WriteLine(msg);
|
---|
[13386] | 526 | }
|
---|
[13407] | 527 |
|
---|
| 528 | [TestMethod]
|
---|
[15857] | 529 | [TestCategory("PersistenceNew")]
|
---|
[13407] | 530 | [TestProperty("Time", "short")]
|
---|
[13409] | 531 | public void TestDouble() {
|
---|
| 532 | var test = new Func<object>(() => { return 42.5d; });
|
---|
| 533 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 534 | serializer.Serialize(test(), tempFile);
|
---|
| 535 | object o = serializer.Deserialize(tempFile);
|
---|
| 536 | double result = (double)o;
|
---|
| 537 | Assert.AreEqual(test(), result);
|
---|
| 538 | Assert.IsTrue(o is double);
|
---|
| 539 |
|
---|
| 540 | string msg = Profile(test);
|
---|
| 541 | Console.WriteLine(msg);
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | [TestMethod]
|
---|
[15857] | 545 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 546 | [TestProperty("Time", "short")]
|
---|
| 547 | public void TestFloat() {
|
---|
| 548 | var test = new Func<object>(() => { return 42.5f; });
|
---|
| 549 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 550 | serializer.Serialize(test(), tempFile);
|
---|
| 551 | object o = serializer.Deserialize(tempFile);
|
---|
| 552 | float result = (float)o;
|
---|
| 553 | Assert.AreEqual(test(), result);
|
---|
| 554 | Assert.IsTrue(o is float);
|
---|
| 555 |
|
---|
| 556 | string msg = Profile(test);
|
---|
| 557 | Console.WriteLine(msg);
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | [TestMethod]
|
---|
[15857] | 561 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 562 | [TestProperty("Time", "short")]
|
---|
| 563 | public void TestDecimal() {
|
---|
| 564 | var test = new Func<object>(() => { return 42.5m; });
|
---|
| 565 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 566 | serializer.Serialize(test(), tempFile);
|
---|
| 567 | object o = serializer.Deserialize(tempFile);
|
---|
| 568 | decimal result = (decimal)o;
|
---|
| 569 | Assert.AreEqual(test(), result);
|
---|
| 570 | Assert.IsTrue(o is decimal);
|
---|
| 571 |
|
---|
| 572 | string msg = Profile(test);
|
---|
| 573 | Console.WriteLine(msg);
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | [TestMethod]
|
---|
[15857] | 577 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 578 | [TestProperty("Time", "short")]
|
---|
| 579 | public void TestLong() {
|
---|
| 580 | var test = new Func<object>(() => { return 42l; });
|
---|
| 581 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 582 | serializer.Serialize(test(), tempFile);
|
---|
| 583 | object o = serializer.Deserialize(tempFile);
|
---|
| 584 | long result = (long)o;
|
---|
| 585 | Assert.AreEqual(test(), result);
|
---|
| 586 | Assert.IsTrue(o is long);
|
---|
| 587 |
|
---|
| 588 | string msg = Profile(test);
|
---|
| 589 | Console.WriteLine(msg);
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 | [TestMethod]
|
---|
[15857] | 593 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 594 | [TestProperty("Time", "short")]
|
---|
| 595 | public void TestUInt() {
|
---|
| 596 | var test = new Func<object>(() => { return 42u; });
|
---|
| 597 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 598 | serializer.Serialize(test(), tempFile);
|
---|
| 599 | object o = serializer.Deserialize(tempFile);
|
---|
| 600 | uint result = (uint)o;
|
---|
| 601 | Assert.AreEqual(test(), result);
|
---|
| 602 | Assert.IsTrue(o is uint);
|
---|
| 603 |
|
---|
| 604 | string msg = Profile(test);
|
---|
| 605 | Console.WriteLine(msg);
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | [TestMethod]
|
---|
[15857] | 609 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 610 | [TestProperty("Time", "short")]
|
---|
| 611 | public void TestShort() {
|
---|
| 612 | var test = new Func<object>(() => { short s = 42; return s; });
|
---|
| 613 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 614 | serializer.Serialize(test(), tempFile);
|
---|
| 615 | object o = serializer.Deserialize(tempFile);
|
---|
| 616 | short result = (short)o;
|
---|
| 617 | Assert.IsTrue(o is short);
|
---|
| 618 | Assert.AreEqual(test(), result);
|
---|
| 619 |
|
---|
| 620 | string msg = Profile(test);
|
---|
| 621 | Console.WriteLine(msg);
|
---|
| 622 | }
|
---|
| 623 |
|
---|
| 624 | [TestMethod]
|
---|
[15857] | 625 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 626 | [TestProperty("Time", "short")]
|
---|
| 627 | public void TestByte() {
|
---|
| 628 | var test = new Func<object>(() => { byte b = 42; return b; });
|
---|
| 629 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 630 | serializer.Serialize(test(), tempFile);
|
---|
| 631 | object o = serializer.Deserialize(tempFile);
|
---|
| 632 | byte result = (byte)o;
|
---|
| 633 | Assert.IsTrue(o is byte);
|
---|
| 634 | Assert.AreEqual(test(), result);
|
---|
| 635 |
|
---|
| 636 | string msg = Profile(test);
|
---|
| 637 | Console.WriteLine(msg);
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | [TestMethod]
|
---|
[15857] | 641 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 642 | [TestProperty("Time", "short")]
|
---|
[13407] | 643 | public void TestEnumSimple() {
|
---|
[13409] | 644 | var test = new Func<object>(() => { return SimpleEnum.two; });
|
---|
| 645 |
|
---|
[13407] | 646 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13409] | 647 | serializer.Serialize(test(), tempFile);
|
---|
[13407] | 648 | object o = serializer.Deserialize(tempFile);
|
---|
| 649 | SimpleEnum result = (SimpleEnum)o;
|
---|
[13409] | 650 | Assert.AreEqual(test(), result);
|
---|
| 651 |
|
---|
| 652 | string msg = Profile(test);
|
---|
| 653 | Console.WriteLine(msg);
|
---|
[13407] | 654 | }
|
---|
| 655 |
|
---|
| 656 | [TestMethod]
|
---|
[15857] | 657 | [TestCategory("PersistenceNew")]
|
---|
[13407] | 658 | [TestProperty("Time", "short")]
|
---|
| 659 | public void TestEnumComplex() {
|
---|
[13409] | 660 | var test = new Func<object>(() => { return ComplexEnum.three; });
|
---|
[13407] | 661 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13409] | 662 | serializer.Serialize(test(), tempFile);
|
---|
[13407] | 663 | object o = serializer.Deserialize(tempFile);
|
---|
| 664 | ComplexEnum result = (ComplexEnum)o;
|
---|
[13409] | 665 | Assert.AreEqual(test(), result);
|
---|
| 666 |
|
---|
| 667 | string msg = Profile(test);
|
---|
| 668 | Console.WriteLine(msg);
|
---|
[13407] | 669 | }
|
---|
| 670 |
|
---|
| 671 | [TestMethod]
|
---|
[15857] | 672 | [TestCategory("PersistenceNew")]
|
---|
[13407] | 673 | [TestProperty("Time", "short")]
|
---|
| 674 | public void TestType() {
|
---|
[13409] | 675 | var test = new Func<object>(() => { return typeof(HeuristicLab.Algorithms.GeneticAlgorithm.GeneticAlgorithm); });
|
---|
[13407] | 676 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13409] | 677 | serializer.Serialize(test(), tempFile);
|
---|
[13407] | 678 | object o = serializer.Deserialize(tempFile);
|
---|
| 679 | Type result = (Type)o;
|
---|
[13409] | 680 | Assert.AreEqual(test(), result);
|
---|
| 681 |
|
---|
| 682 | string msg = Profile(test);
|
---|
| 683 | Console.WriteLine(msg);
|
---|
[13407] | 684 | }
|
---|
| 685 |
|
---|
[13409] | 686 | [TestMethod]
|
---|
[15857] | 687 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 688 | [TestProperty("Time", "short")]
|
---|
| 689 | public void TestBytes() {
|
---|
| 690 | var test = new Func<byte[]>(() => { return new byte[] { 3, 1 }; });
|
---|
| 691 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 692 | serializer.Serialize(test(), tempFile);
|
---|
| 693 | object o = serializer.Deserialize(tempFile);
|
---|
| 694 | byte[] result = (byte[])o;
|
---|
| 695 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 696 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 697 |
|
---|
| 698 | string msg = Profile(test);
|
---|
| 699 | Console.WriteLine(msg);
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 | [TestMethod]
|
---|
[15857] | 703 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 704 | [TestProperty("Time", "short")]
|
---|
[14537] | 705 | public void TestSBytes() {
|
---|
| 706 | var test = new Func<sbyte[]>(() => { return new sbyte[] { 3, 1 }; });
|
---|
| 707 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 708 | serializer.Serialize(test(), tempFile);
|
---|
| 709 | object o = serializer.Deserialize(tempFile);
|
---|
| 710 | sbyte[] result = (sbyte[])o;
|
---|
| 711 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 712 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 713 |
|
---|
| 714 | string msg = Profile(test);
|
---|
| 715 | Console.WriteLine(msg);
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | [TestMethod]
|
---|
[15857] | 719 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 720 | [TestProperty("Time", "short")]
|
---|
| 721 | public void TestChars() {
|
---|
| 722 | var test = new Func<char[]>(() => { return new char[] { 'a', 'b' }; });
|
---|
| 723 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 724 | serializer.Serialize(test(), tempFile);
|
---|
| 725 | object o = serializer.Deserialize(tempFile);
|
---|
| 726 | char[] result = (char[])o;
|
---|
| 727 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 728 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 729 |
|
---|
| 730 | string msg = Profile(test);
|
---|
| 731 | Console.WriteLine(msg);
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | [TestMethod]
|
---|
[15857] | 735 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 736 | [TestProperty("Time", "short")]
|
---|
| 737 | public void TestShorts() {
|
---|
| 738 | var test = new Func<short[]>(() => { return new short[] { 3, 1 }; });
|
---|
| 739 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 740 | serializer.Serialize(test(), tempFile);
|
---|
| 741 | object o = serializer.Deserialize(tempFile);
|
---|
| 742 | short[] result = (short[])o;
|
---|
| 743 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 744 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 745 |
|
---|
| 746 | string msg = Profile(test);
|
---|
| 747 | Console.WriteLine(msg);
|
---|
| 748 | }
|
---|
| 749 |
|
---|
| 750 | [TestMethod]
|
---|
[15857] | 751 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 752 | [TestProperty("Time", "short")]
|
---|
| 753 | public void TestUShorts() {
|
---|
| 754 | var test = new Func<ushort[]>(() => { return new ushort[] { 3, 1 }; });
|
---|
| 755 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 756 | serializer.Serialize(test(), tempFile);
|
---|
| 757 | object o = serializer.Deserialize(tempFile);
|
---|
| 758 | ushort[] result = (ushort[])o;
|
---|
| 759 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 760 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 761 |
|
---|
| 762 | string msg = Profile(test);
|
---|
| 763 | Console.WriteLine(msg);
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 | [TestMethod]
|
---|
[15857] | 767 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 768 | [TestProperty("Time", "short")]
|
---|
[13409] | 769 | public void TestString() {
|
---|
| 770 | var test = new Func<object>(() => { return "Hello World!"; });
|
---|
| 771 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 772 | serializer.Serialize(test(), tempFile);
|
---|
| 773 | object o = serializer.Deserialize(tempFile);
|
---|
| 774 | string result = (string)o;
|
---|
| 775 | Assert.AreEqual(test(), result);
|
---|
| 776 |
|
---|
| 777 | string msg = Profile(test);
|
---|
| 778 | Console.WriteLine(msg);
|
---|
| 779 | }
|
---|
| 780 |
|
---|
| 781 | [TestMethod]
|
---|
[15857] | 782 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 783 | [TestProperty("Time", "short")]
|
---|
| 784 | public void TestColor() {
|
---|
[14537] | 785 | var test = new Func<object>(() => { return Color.FromArgb(12, 34, 56, 78); });
|
---|
[13409] | 786 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 787 | serializer.Serialize(test(), tempFile);
|
---|
| 788 | object o = serializer.Deserialize(tempFile);
|
---|
| 789 | Color result = (Color)o;
|
---|
| 790 | Assert.AreEqual(test(), result);
|
---|
| 791 |
|
---|
| 792 | string msg = Profile(test);
|
---|
| 793 | Console.WriteLine(msg);
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | [TestMethod]
|
---|
[15857] | 797 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 798 | [TestProperty("Time", "short")]
|
---|
| 799 | public void TestPoint() {
|
---|
| 800 | var test = new Func<object>(() => { return new Point(3, 4); });
|
---|
| 801 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 802 | serializer.Serialize(test(), tempFile);
|
---|
| 803 | object o = serializer.Deserialize(tempFile);
|
---|
| 804 | Point result = (Point)o;
|
---|
| 805 | Assert.AreEqual(((Point)test()).X, result.X);
|
---|
| 806 | Assert.AreEqual(((Point)test()).Y, result.Y);
|
---|
| 807 |
|
---|
| 808 | string msg = Profile(test);
|
---|
| 809 | Console.WriteLine(msg);
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | [TestMethod]
|
---|
[15857] | 813 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 814 | [TestProperty("Time", "short")]
|
---|
| 815 | public void TestBoolArray() {
|
---|
| 816 | var test = new Func<bool[]>(() => { return new[] { true, false, true }; });
|
---|
| 817 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 818 | serializer.Serialize(test(), tempFile);
|
---|
| 819 | object o = serializer.Deserialize(tempFile);
|
---|
| 820 | bool[] result = (bool[])o;
|
---|
| 821 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 822 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 823 | Assert.AreEqual(test()[2], result[2]);
|
---|
| 824 |
|
---|
| 825 | string msg = Profile(test);
|
---|
| 826 | Console.WriteLine(msg);
|
---|
| 827 | }
|
---|
| 828 |
|
---|
| 829 | [TestMethod]
|
---|
[15857] | 830 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 831 | [TestProperty("Time", "short")]
|
---|
| 832 | public void TestIntArray() {
|
---|
| 833 | var test = new Func<int[]>(() => { return new[] { 41, 22, 13 }; });
|
---|
| 834 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 835 | serializer.Serialize(test(), tempFile);
|
---|
| 836 | object o = serializer.Deserialize(tempFile);
|
---|
| 837 | int[] result = (int[])o;
|
---|
| 838 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 839 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 840 | Assert.AreEqual(test()[2], result[2]);
|
---|
| 841 |
|
---|
| 842 | string msg = Profile(test);
|
---|
| 843 | Console.WriteLine(msg);
|
---|
| 844 | }
|
---|
| 845 |
|
---|
| 846 | [TestMethod]
|
---|
[15857] | 847 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 848 | [TestProperty("Time", "short")]
|
---|
| 849 | public void TestLongArray() {
|
---|
| 850 | var test = new Func<long[]>(() => { return new[] { 414481188112191633l, 245488586662l, 13546881335845865l }; });
|
---|
| 851 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 852 | serializer.Serialize(test(), tempFile);
|
---|
| 853 | object o = serializer.Deserialize(tempFile);
|
---|
| 854 | long[] result = (long[])o;
|
---|
| 855 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 856 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 857 | Assert.AreEqual(test()[2], result[2]);
|
---|
| 858 |
|
---|
| 859 | string msg = Profile(test);
|
---|
| 860 | Console.WriteLine(msg);
|
---|
| 861 | }
|
---|
| 862 |
|
---|
| 863 | [TestMethod]
|
---|
[15857] | 864 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 865 | [TestProperty("Time", "short")]
|
---|
| 866 | public void TestDoubleArray() {
|
---|
| 867 | var test = new Func<double[]>(() => { return new[] { 41.5, 22.7, 13.8 }; });
|
---|
| 868 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 869 | serializer.Serialize(test(), tempFile);
|
---|
| 870 | object o = serializer.Deserialize(tempFile);
|
---|
| 871 | double[] result = (double[])o;
|
---|
| 872 | Assert.AreEqual(test()[0], result[0]);
|
---|
| 873 | Assert.AreEqual(test()[1], result[1]);
|
---|
| 874 | Assert.AreEqual(test()[2], result[2]);
|
---|
| 875 |
|
---|
| 876 | string msg = Profile(test);
|
---|
| 877 | Console.WriteLine(msg);
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | [TestMethod]
|
---|
[15857] | 881 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 882 | [TestProperty("Time", "short")]
|
---|
| 883 | public void TestObjectArray() {
|
---|
| 884 | var test = new Func<SimpleClass[]>(() => {
|
---|
| 885 | return new[] { new SimpleClass() { x = 42, y = 43 },
|
---|
| 886 | new SimpleClass() { x = 44.44, y = 5677 },
|
---|
| 887 | new SimpleClass() { x = 533.33, y = 2345 } };
|
---|
| 888 | });
|
---|
| 889 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 890 | serializer.Serialize(test(), tempFile);
|
---|
| 891 | object o = serializer.Deserialize(tempFile);
|
---|
| 892 | SimpleClass[] result = (SimpleClass[])o;
|
---|
| 893 | Assert.AreEqual(test()[0].x, result[0].x);
|
---|
| 894 | Assert.AreEqual(test()[0].y, result[0].y);
|
---|
| 895 | Assert.AreEqual(test()[1].x, result[1].x);
|
---|
| 896 | Assert.AreEqual(test()[1].y, result[1].y);
|
---|
| 897 | Assert.AreEqual(test()[2].x, result[2].x);
|
---|
| 898 | Assert.AreEqual(test()[2].y, result[2].y);
|
---|
| 899 |
|
---|
| 900 | string msg = Profile(test);
|
---|
| 901 | Console.WriteLine(msg);
|
---|
| 902 | }
|
---|
| 903 |
|
---|
| 904 | [TestMethod]
|
---|
[15857] | 905 | [TestCategory("PersistenceNew")]
|
---|
[13409] | 906 | [TestProperty("Time", "short")]
|
---|
[14537] | 907 | public void TestStack() {
|
---|
| 908 | var test = new Func<Stack>(() => {
|
---|
| 909 | return new Stack(new int[] { 1, 2, 3 });
|
---|
| 910 | });
|
---|
| 911 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 912 | serializer.Serialize(test(), tempFile);
|
---|
| 913 | object o = serializer.Deserialize(tempFile);
|
---|
| 914 | Stack result = (Stack)o;
|
---|
| 915 | var actualStack = test();
|
---|
| 916 | Assert.AreEqual(actualStack.Pop(), result.Pop());
|
---|
| 917 | Assert.AreEqual(actualStack.Pop(), result.Pop());
|
---|
| 918 | Assert.AreEqual(actualStack.Pop(), result.Pop());
|
---|
| 919 |
|
---|
| 920 | string msg = Profile(test);
|
---|
| 921 | Console.WriteLine(msg);
|
---|
| 922 | }
|
---|
| 923 |
|
---|
| 924 | [TestMethod]
|
---|
[15857] | 925 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 926 | [TestProperty("Time", "short")]
|
---|
| 927 | public void TestArrayOfStack() {
|
---|
| 928 | var test = new Func<object[]>(() => {
|
---|
| 929 | return new object[] {
|
---|
| 930 | new Stack(new int[] { 1, 2, 3 }),
|
---|
| 931 | new Stack<int>(new int[] { 1, 2, 3 }),
|
---|
| 932 | };
|
---|
| 933 | });
|
---|
| 934 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 935 | serializer.Serialize(test(), tempFile);
|
---|
| 936 | object o = serializer.Deserialize(tempFile);
|
---|
| 937 | var result = (object[])o;
|
---|
| 938 | var firstStack = (Stack)result[0];
|
---|
| 939 | var secondStack = (Stack<int>)result[1];
|
---|
| 940 | var actual = test();
|
---|
| 941 | var actualFirst = (Stack)actual[0];
|
---|
| 942 | var actualSecond = (Stack<int>)actual[1];
|
---|
| 943 |
|
---|
| 944 | Assert.AreEqual(actualFirst.Pop(), firstStack.Pop());
|
---|
| 945 | Assert.AreEqual(actualFirst.Pop(), firstStack.Pop());
|
---|
| 946 | Assert.AreEqual(actualFirst.Pop(), firstStack.Pop());
|
---|
| 947 | Assert.AreEqual(actualSecond.Pop(), secondStack.Pop());
|
---|
| 948 | Assert.AreEqual(actualSecond.Pop(), secondStack.Pop());
|
---|
| 949 | Assert.AreEqual(actualSecond.Pop(), secondStack.Pop());
|
---|
| 950 |
|
---|
| 951 | string msg = Profile(test);
|
---|
| 952 | Console.WriteLine(msg);
|
---|
| 953 | }
|
---|
| 954 |
|
---|
| 955 |
|
---|
| 956 | [TestMethod]
|
---|
[15857] | 957 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 958 | [TestProperty("Time", "short")]
|
---|
[13409] | 959 | public void TestIntValueArray() {
|
---|
| 960 | var test = new Func<IntValue[]>(() => { return new[] { new IntValue(41), new IntValue(22), new IntValue(13) }; });
|
---|
| 961 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 962 | serializer.Serialize(test(), tempFile);
|
---|
| 963 | object o = serializer.Deserialize(tempFile);
|
---|
| 964 | IntValue[] result = (IntValue[])o;
|
---|
[14537] | 965 | Assert.AreEqual(test()[0].Value, result[0].Value);
|
---|
| 966 | Assert.AreEqual(test()[1].Value, result[1].Value);
|
---|
| 967 | Assert.AreEqual(test()[2].Value, result[2].Value);
|
---|
[13409] | 968 |
|
---|
| 969 | string msg = Profile(test);
|
---|
| 970 | Console.WriteLine(msg);
|
---|
| 971 | }
|
---|
[14537] | 972 |
|
---|
| 973 | [TestMethod]
|
---|
[15857] | 974 | [TestCategory("PersistenceNew")]
|
---|
[14537] | 975 | [TestProperty("Time", "short")]
|
---|
| 976 | public void TestIntValueArrayArray() {
|
---|
| 977 | var test = new Func<IntValue[][]>(() => { return new IntValue[][] { new IntValue[] { new IntValue(41), new IntValue(22), new IntValue(13) } }; });
|
---|
| 978 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 979 | serializer.Serialize(test(), tempFile);
|
---|
| 980 | object o = serializer.Deserialize(tempFile);
|
---|
| 981 | IntValue[][] result = (IntValue[][])o;
|
---|
| 982 | Assert.AreEqual(test()[0][0].Value, result[0][0].Value);
|
---|
| 983 | Assert.AreEqual(test()[0][1].Value, result[0][1].Value);
|
---|
| 984 | Assert.AreEqual(test()[0][2].Value, result[0][2].Value);
|
---|
| 985 |
|
---|
| 986 | string msg = Profile(test);
|
---|
| 987 | Console.WriteLine(msg);
|
---|
| 988 | }
|
---|
[13386] | 989 | #endregion
|
---|
| 990 |
|
---|
[15857] | 991 | #region Old Persistence Tests
|
---|
[13386] | 992 | [TestMethod]
|
---|
[15857] | 993 | [TestCategory("PersistenceNew")]
|
---|
[13386] | 994 | [TestProperty("Time", "short")]
|
---|
| 995 | public void ComplexStorable() {
|
---|
| 996 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 997 | Root r = InitializeComplexStorable();
|
---|
[13386] | 998 | serializer.Serialize(r, tempFile);
|
---|
| 999 | Root newR = (Root)serializer.Deserialize(tempFile);
|
---|
| 1000 | CompareComplexStorables(r, newR);
|
---|
[6846] | 1001 | }
|
---|
| 1002 |
|
---|
| 1003 | private static void CompareComplexStorables(Root r, Root newR) {
|
---|
| 1004 | Assert.AreEqual(
|
---|
| 1005 | DebugStringGenerator.Serialize(r),
|
---|
| 1006 | DebugStringGenerator.Serialize(newR));
|
---|
| 1007 | Assert.AreSame(newR, newR.selfReferences[0]);
|
---|
| 1008 | Assert.AreNotSame(r, newR);
|
---|
| 1009 | Assert.AreEqual(r.myEnum, TestEnum.va1);
|
---|
| 1010 | Assert.AreEqual(r.i[0], 7);
|
---|
| 1011 | Assert.AreEqual(r.i[1], 5);
|
---|
| 1012 | Assert.AreEqual(r.i[2], 6);
|
---|
| 1013 | Assert.AreEqual(r.s, "new value");
|
---|
| 1014 | Assert.AreEqual(r.intArray[0], 3);
|
---|
| 1015 | Assert.AreEqual(r.intArray[1], 2);
|
---|
| 1016 | Assert.AreEqual(r.intArray[2], 1);
|
---|
| 1017 | Assert.AreEqual(r.intList[0], 9);
|
---|
| 1018 | Assert.AreEqual(r.intList[1], 8);
|
---|
| 1019 | Assert.AreEqual(r.intList[2], 7);
|
---|
| 1020 | Assert.AreEqual(r.multiDimArray[0, 0], 5);
|
---|
| 1021 | Assert.AreEqual(r.multiDimArray[0, 1], 4);
|
---|
| 1022 | Assert.AreEqual(r.multiDimArray[0, 2], 3);
|
---|
| 1023 | Assert.AreEqual(r.multiDimArray[1, 0], 1);
|
---|
| 1024 | Assert.AreEqual(r.multiDimArray[1, 1], 4);
|
---|
| 1025 | Assert.AreEqual(r.multiDimArray[1, 2], 6);
|
---|
| 1026 | Assert.IsFalse(r.boolean);
|
---|
| 1027 | Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10);
|
---|
| 1028 | Assert.AreEqual(r.kvp.Key, "string key");
|
---|
| 1029 | Assert.AreEqual(r.kvp.Value, 321);
|
---|
| 1030 | Assert.IsNull(r.uninitialized);
|
---|
| 1031 | Assert.AreEqual(newR.myEnum, TestEnum.va1);
|
---|
| 1032 | Assert.AreEqual(newR.i[0], 7);
|
---|
| 1033 | Assert.AreEqual(newR.i[1], 5);
|
---|
| 1034 | Assert.AreEqual(newR.i[2], 6);
|
---|
| 1035 | Assert.AreEqual(newR.s, "new value");
|
---|
| 1036 | Assert.AreEqual(newR.intArray[0], 3);
|
---|
| 1037 | Assert.AreEqual(newR.intArray[1], 2);
|
---|
| 1038 | Assert.AreEqual(newR.intArray[2], 1);
|
---|
| 1039 | Assert.AreEqual(newR.intList[0], 9);
|
---|
| 1040 | Assert.AreEqual(newR.intList[1], 8);
|
---|
| 1041 | Assert.AreEqual(newR.intList[2], 7);
|
---|
| 1042 | Assert.AreEqual(newR.multiDimArray[0, 0], 5);
|
---|
| 1043 | Assert.AreEqual(newR.multiDimArray[0, 1], 4);
|
---|
| 1044 | Assert.AreEqual(newR.multiDimArray[0, 2], 3);
|
---|
| 1045 | Assert.AreEqual(newR.multiDimArray[1, 0], 1);
|
---|
| 1046 | Assert.AreEqual(newR.multiDimArray[1, 1], 4);
|
---|
| 1047 | Assert.AreEqual(newR.multiDimArray[1, 2], 6);
|
---|
| 1048 | Assert.AreEqual(newR.intStack.Pop(), 3);
|
---|
| 1049 | Assert.AreEqual(newR.intStack.Pop(), 2);
|
---|
| 1050 | Assert.AreEqual(newR.intStack.Pop(), 1);
|
---|
| 1051 | Assert.IsFalse(newR.boolean);
|
---|
| 1052 | Assert.IsTrue((DateTime.Now - newR.dateTime).TotalSeconds < 10);
|
---|
| 1053 | Assert.AreEqual(newR.kvp.Key, "string key");
|
---|
| 1054 | Assert.AreEqual(newR.kvp.Value, 321);
|
---|
| 1055 | Assert.IsNull(newR.uninitialized);
|
---|
| 1056 | }
|
---|
| 1057 |
|
---|
| 1058 | private static Root InitializeComplexStorable() {
|
---|
| 1059 | Root r = new Root();
|
---|
| 1060 | r.intStack.Push(1);
|
---|
| 1061 | r.intStack.Push(2);
|
---|
| 1062 | r.intStack.Push(3);
|
---|
| 1063 | r.selfReferences = new List<Root> { r, r };
|
---|
| 1064 | r.c = new Custom { r = r };
|
---|
| 1065 | r.dict.Add("one", 1);
|
---|
| 1066 | r.dict.Add("two", 2);
|
---|
| 1067 | r.dict.Add("three", 3);
|
---|
| 1068 | r.myEnum = TestEnum.va1;
|
---|
| 1069 | r.i = new[] { 7, 5, 6 };
|
---|
| 1070 | r.s = "new value";
|
---|
| 1071 | r.intArray = new ArrayList { 3, 2, 1 };
|
---|
| 1072 | r.intList = new List<int> { 9, 8, 7 };
|
---|
| 1073 | r.multiDimArray = new double[,] { { 5, 4, 3 }, { 1, 4, 6 } };
|
---|
| 1074 | r.boolean = false;
|
---|
| 1075 | r.dateTime = DateTime.Now;
|
---|
| 1076 | r.kvp = new KeyValuePair<string, int>("string key", 321);
|
---|
| 1077 | r.uninitialized = null;
|
---|
| 1078 |
|
---|
| 1079 | return r;
|
---|
| 1080 | }
|
---|
| 1081 |
|
---|
| 1082 | [TestMethod]
|
---|
[15857] | 1083 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1084 | [TestProperty("Time", "short")]
|
---|
[6846] | 1085 | public void SelfReferences() {
|
---|
[13386] | 1086 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1087 | C c = new C();
|
---|
| 1088 | C[][] cs = new C[2][];
|
---|
| 1089 | cs[0] = new C[] { c };
|
---|
| 1090 | cs[1] = new C[] { c };
|
---|
| 1091 | c.allCs = cs;
|
---|
| 1092 | c.kvpList = new KeyValuePair<List<C>, C>(new List<C> { c }, c);
|
---|
[13386] | 1093 | serializer.Serialize(cs, tempFile);
|
---|
| 1094 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1095 | Assert.AreEqual(
|
---|
| 1096 | DebugStringGenerator.Serialize(cs),
|
---|
| 1097 | DebugStringGenerator.Serialize(o));
|
---|
| 1098 | Assert.AreSame(c, c.allCs[0][0]);
|
---|
| 1099 | Assert.AreSame(c, c.allCs[1][0]);
|
---|
| 1100 | Assert.AreSame(c, c.kvpList.Key[0]);
|
---|
| 1101 | Assert.AreSame(c, c.kvpList.Value);
|
---|
| 1102 | C[][] newCs = (C[][])o;
|
---|
| 1103 | C newC = newCs[0][0];
|
---|
| 1104 | Assert.AreSame(newC, newC.allCs[0][0]);
|
---|
| 1105 | Assert.AreSame(newC, newC.allCs[1][0]);
|
---|
| 1106 | Assert.AreSame(newC, newC.kvpList.Key[0]);
|
---|
| 1107 | Assert.AreSame(newC, newC.kvpList.Value);
|
---|
| 1108 | }
|
---|
| 1109 |
|
---|
| 1110 | [TestMethod]
|
---|
[15857] | 1111 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1112 | [TestProperty("Time", "short")]
|
---|
[6846] | 1113 | public void ArrayCreation() {
|
---|
[13386] | 1114 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1115 | ArrayList[] arrayListArray = new ArrayList[4];
|
---|
| 1116 | arrayListArray[0] = new ArrayList();
|
---|
| 1117 | arrayListArray[0].Add(arrayListArray);
|
---|
| 1118 | arrayListArray[0].Add(arrayListArray);
|
---|
| 1119 | arrayListArray[1] = new ArrayList();
|
---|
| 1120 | arrayListArray[1].Add(arrayListArray);
|
---|
| 1121 | arrayListArray[2] = new ArrayList();
|
---|
| 1122 | arrayListArray[2].Add(arrayListArray);
|
---|
| 1123 | arrayListArray[2].Add(arrayListArray);
|
---|
[15857] | 1124 | Array a = Array.CreateInstance(
|
---|
| 1125 | typeof(object),
|
---|
| 1126 | new[] { 1, 2 }, new[] { 3, 4 });
|
---|
| 1127 | arrayListArray[2].Add(a);
|
---|
[13386] | 1128 | serializer.Serialize(arrayListArray, tempFile);
|
---|
| 1129 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1130 | Assert.AreEqual(
|
---|
| 1131 | DebugStringGenerator.Serialize(arrayListArray),
|
---|
| 1132 | DebugStringGenerator.Serialize(o));
|
---|
| 1133 | ArrayList[] newArray = (ArrayList[])o;
|
---|
| 1134 | Assert.AreSame(arrayListArray, arrayListArray[0][0]);
|
---|
| 1135 | Assert.AreSame(arrayListArray, arrayListArray[2][1]);
|
---|
| 1136 | Assert.AreSame(newArray, newArray[0][0]);
|
---|
| 1137 | Assert.AreSame(newArray, newArray[2][1]);
|
---|
| 1138 | }
|
---|
| 1139 |
|
---|
| 1140 | [TestMethod]
|
---|
[15857] | 1141 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1142 | [TestProperty("Time", "short")]
|
---|
[6846] | 1143 | public void CustomSerializationProperty() {
|
---|
[13386] | 1144 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1145 | Manager m = new Manager();
|
---|
[13386] | 1146 | serializer.Serialize(m, tempFile);
|
---|
| 1147 | Manager newM = (Manager)serializer.Deserialize(tempFile);
|
---|
[6846] | 1148 | Assert.AreNotEqual(
|
---|
| 1149 | DebugStringGenerator.Serialize(m),
|
---|
| 1150 | DebugStringGenerator.Serialize(newM));
|
---|
| 1151 | Assert.AreEqual(m.dbl, newM.dbl);
|
---|
| 1152 | Assert.AreEqual(m.lastLoadTime, new DateTime());
|
---|
| 1153 | Assert.AreNotEqual(newM.lastLoadTime, new DateTime());
|
---|
| 1154 | Assert.IsTrue((DateTime.Now - newM.lastLoadTime).TotalSeconds < 10);
|
---|
| 1155 | }
|
---|
| 1156 |
|
---|
| 1157 | [TestMethod]
|
---|
[15857] | 1158 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1159 | [TestProperty("Time", "short")]
|
---|
[6846] | 1160 | public void Primitives() {
|
---|
[13386] | 1161 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1162 | PrimitivesTest sdt = new PrimitivesTest();
|
---|
[13386] | 1163 | serializer.Serialize(sdt, tempFile);
|
---|
| 1164 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1165 | Assert.AreEqual(
|
---|
| 1166 | DebugStringGenerator.Serialize(sdt),
|
---|
| 1167 | DebugStringGenerator.Serialize(o));
|
---|
| 1168 | }
|
---|
| 1169 |
|
---|
| 1170 | [TestMethod]
|
---|
[15857] | 1171 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1172 | [TestProperty("Time", "short")]
|
---|
[6846] | 1173 | public void MultiDimensionalArray() {
|
---|
[13386] | 1174 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1175 | string[,] mDimString = new string[,] {
|
---|
| 1176 | {"ora", "et", "labora"},
|
---|
| 1177 | {"Beten", "und", "Arbeiten"}
|
---|
| 1178 | };
|
---|
[13386] | 1179 | serializer.Serialize(mDimString, tempFile);
|
---|
| 1180 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1181 | Assert.AreEqual(
|
---|
| 1182 | DebugStringGenerator.Serialize(mDimString),
|
---|
| 1183 | DebugStringGenerator.Serialize(o));
|
---|
| 1184 | }
|
---|
| 1185 |
|
---|
[14711] | 1186 | [StorableType("87A331AF-14DC-48B3-B577-D49065743BE6")]
|
---|
[6846] | 1187 | public class NestedType {
|
---|
| 1188 | [Storable]
|
---|
| 1189 | private string value = "value";
|
---|
| 1190 | public override bool Equals(object obj) {
|
---|
| 1191 | NestedType nt = obj as NestedType;
|
---|
| 1192 | if (nt == null)
|
---|
| 1193 | throw new NotSupportedException();
|
---|
| 1194 | return nt.value == value;
|
---|
| 1195 | }
|
---|
| 1196 | public override int GetHashCode() {
|
---|
| 1197 | return value.GetHashCode();
|
---|
| 1198 | }
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
| 1201 | [TestMethod]
|
---|
[15857] | 1202 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1203 | [TestProperty("Time", "short")]
|
---|
[6846] | 1204 | public void NestedTypeTest() {
|
---|
[13386] | 1205 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1206 | NestedType t = new NestedType();
|
---|
[13386] | 1207 | serializer.Serialize(t, tempFile);
|
---|
| 1208 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1209 | Assert.AreEqual(
|
---|
| 1210 | DebugStringGenerator.Serialize(t),
|
---|
| 1211 | DebugStringGenerator.Serialize(o));
|
---|
| 1212 | Assert.IsTrue(t.Equals(o));
|
---|
| 1213 | }
|
---|
| 1214 |
|
---|
| 1215 |
|
---|
| 1216 | [TestMethod]
|
---|
[15857] | 1217 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1218 | [TestProperty("Time", "short")]
|
---|
[6846] | 1219 | public void SimpleArray() {
|
---|
[13386] | 1220 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1221 | string[] strings = { "ora", "et", "labora" };
|
---|
[13386] | 1222 | serializer.Serialize(strings, tempFile);
|
---|
| 1223 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1224 | Assert.AreEqual(
|
---|
| 1225 | DebugStringGenerator.Serialize(strings),
|
---|
| 1226 | DebugStringGenerator.Serialize(o));
|
---|
| 1227 | }
|
---|
| 1228 |
|
---|
| 1229 | [TestMethod]
|
---|
[15857] | 1230 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1231 | [TestProperty("Time", "short")]
|
---|
[6846] | 1232 | public void PrimitiveRoot() {
|
---|
[13386] | 1233 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 1234 | serializer.Serialize(12.3f, tempFile);
|
---|
| 1235 | object o = serializer.Deserialize(tempFile);
|
---|
[6846] | 1236 | Assert.AreEqual(
|
---|
| 1237 | DebugStringGenerator.Serialize(12.3f),
|
---|
| 1238 | DebugStringGenerator.Serialize(o));
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
| 1241 | private string formatFullMemberName(MemberInfo mi) {
|
---|
| 1242 | return new StringBuilder()
|
---|
| 1243 | .Append(mi.DeclaringType.Assembly.GetName().Name)
|
---|
| 1244 | .Append(": ")
|
---|
| 1245 | .Append(mi.DeclaringType.Namespace)
|
---|
| 1246 | .Append('.')
|
---|
| 1247 | .Append(mi.DeclaringType.Name)
|
---|
| 1248 | .Append('.')
|
---|
| 1249 | .Append(mi.Name).ToString();
|
---|
| 1250 | }
|
---|
| 1251 |
|
---|
| 1252 | public void CodingConventions() {
|
---|
| 1253 | List<string> lowerCaseMethodNames = new List<string>();
|
---|
| 1254 | List<string> lowerCaseProperties = new List<string>();
|
---|
| 1255 | List<string> lowerCaseFields = new List<string>();
|
---|
[6912] | 1256 | foreach (Assembly a in PluginLoader.Assemblies) {
|
---|
[6846] | 1257 | if (!a.GetName().Name.StartsWith("HeuristicLab"))
|
---|
| 1258 | continue;
|
---|
| 1259 | foreach (Type t in a.GetTypes()) {
|
---|
| 1260 | foreach (MemberInfo mi in t.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) {
|
---|
| 1261 | if (mi.DeclaringType.Name.StartsWith("<>"))
|
---|
| 1262 | continue;
|
---|
| 1263 | if (char.IsLower(mi.Name[0])) {
|
---|
| 1264 | if (mi.MemberType == MemberTypes.Field)
|
---|
| 1265 | lowerCaseFields.Add(formatFullMemberName(mi));
|
---|
| 1266 | if (mi.MemberType == MemberTypes.Property)
|
---|
| 1267 | lowerCaseProperties.Add(formatFullMemberName(mi));
|
---|
| 1268 | if (mi.MemberType == MemberTypes.Method &&
|
---|
| 1269 | !mi.Name.StartsWith("get_") &&
|
---|
| 1270 | !mi.Name.StartsWith("set_") &&
|
---|
| 1271 | !mi.Name.StartsWith("add_") &&
|
---|
| 1272 | !mi.Name.StartsWith("remove_") &&
|
---|
| 1273 | !mi.Name.StartsWith("op_"))
|
---|
| 1274 | lowerCaseMethodNames.Add(formatFullMemberName(mi));
|
---|
| 1275 | }
|
---|
| 1276 | }
|
---|
| 1277 | }
|
---|
| 1278 | }
|
---|
| 1279 | //Assert.AreEqual("", lowerCaseFields.Aggregate("", (a, b) => a + "\r\n" + b));
|
---|
| 1280 | Assert.AreEqual("", lowerCaseMethodNames.Aggregate("", (a, b) => a + "\r\n" + b));
|
---|
| 1281 | Assert.AreEqual("", lowerCaseProperties.Aggregate("", (a, b) => a + "\r\n" + b));
|
---|
| 1282 | }
|
---|
| 1283 |
|
---|
| 1284 | [TestMethod]
|
---|
[15857] | 1285 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1286 | [TestProperty("Time", "short")]
|
---|
[6846] | 1287 | public void Enums() {
|
---|
[13386] | 1288 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1289 | EnumTest et = new EnumTest();
|
---|
| 1290 | et.simpleEnum = SimpleEnum.two;
|
---|
| 1291 | et.complexEnum = ComplexEnum.three;
|
---|
| 1292 | et.trickyEnum = TrickyEnum.two | TrickyEnum.one;
|
---|
[13386] | 1293 | serializer.Serialize(et, tempFile);
|
---|
| 1294 | EnumTest newEt = (EnumTest)serializer.Deserialize(tempFile);
|
---|
[6846] | 1295 | Assert.AreEqual(et.simpleEnum, SimpleEnum.two);
|
---|
| 1296 | Assert.AreEqual(et.complexEnum, ComplexEnum.three);
|
---|
| 1297 | Assert.AreEqual(et.trickyEnum, (TrickyEnum)3);
|
---|
| 1298 | }
|
---|
| 1299 |
|
---|
| 1300 | [TestMethod]
|
---|
[15857] | 1301 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1302 | [TestProperty("Time", "short")]
|
---|
[6846] | 1303 | public void TestAliasingWithOverriddenEquals() {
|
---|
[13386] | 1304 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1305 | List<IntWrapper> ints = new List<IntWrapper>();
|
---|
| 1306 | ints.Add(new IntWrapper(1));
|
---|
| 1307 | ints.Add(new IntWrapper(1));
|
---|
| 1308 | Assert.AreEqual(ints[0], ints[1]);
|
---|
| 1309 | Assert.AreNotSame(ints[0], ints[1]);
|
---|
[13386] | 1310 | serializer.Serialize(ints, tempFile);
|
---|
| 1311 | List<IntWrapper> newInts = (List<IntWrapper>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1312 | Assert.AreEqual(newInts[0].Value, 1);
|
---|
| 1313 | Assert.AreEqual(newInts[1].Value, 1);
|
---|
| 1314 | Assert.AreEqual(newInts[0], newInts[1]);
|
---|
| 1315 | Assert.AreNotSame(newInts[0], newInts[1]);
|
---|
| 1316 | }
|
---|
| 1317 |
|
---|
| 1318 | [TestMethod]
|
---|
[15857] | 1319 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1320 | [TestProperty("Time", "short")]
|
---|
[6846] | 1321 | public void NonDefaultConstructorTest() {
|
---|
[13386] | 1322 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1323 | NonDefaultConstructorClass c = new NonDefaultConstructorClass(1);
|
---|
| 1324 | try {
|
---|
[13386] | 1325 | serializer.Serialize(c, tempFile);
|
---|
[6846] | 1326 | Assert.Fail("Exception not thrown");
|
---|
[14537] | 1327 | } catch (PersistenceException) {
|
---|
[6846] | 1328 | }
|
---|
| 1329 | }
|
---|
| 1330 |
|
---|
| 1331 | [TestMethod]
|
---|
[15857] | 1332 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1333 | [TestProperty("Time", "short")]
|
---|
[6846] | 1334 | public void TestSavingException() {
|
---|
[13386] | 1335 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1336 | List<int> list = new List<int> { 1, 2, 3 };
|
---|
[13386] | 1337 | serializer.Serialize(list, tempFile);
|
---|
[6846] | 1338 | NonSerializable s = new NonSerializable();
|
---|
| 1339 | try {
|
---|
[13386] | 1340 | serializer.Serialize(s, tempFile);
|
---|
[6846] | 1341 | Assert.Fail("Exception expected");
|
---|
[14537] | 1342 | } catch (PersistenceException) { }
|
---|
[13386] | 1343 | List<int> newList = (List<int>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1344 | Assert.AreEqual(list[0], newList[0]);
|
---|
| 1345 | Assert.AreEqual(list[1], newList[1]);
|
---|
| 1346 | }
|
---|
| 1347 |
|
---|
| 1348 | [TestMethod]
|
---|
[15857] | 1349 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1350 | [TestProperty("Time", "short")]
|
---|
[6846] | 1351 | public void TestTypeStringConversion() {
|
---|
| 1352 | string name = typeof(List<int>[]).AssemblyQualifiedName;
|
---|
| 1353 | string shortName =
|
---|
| 1354 | "System.Collections.Generic.List`1[[System.Int32, mscorlib]][], mscorlib";
|
---|
| 1355 | Assert.AreEqual(name, TypeNameParser.Parse(name).ToString());
|
---|
| 1356 | Assert.AreEqual(shortName, TypeNameParser.Parse(name).ToString(false));
|
---|
| 1357 | Assert.AreEqual(shortName, typeof(List<int>[]).VersionInvariantName());
|
---|
| 1358 | }
|
---|
| 1359 |
|
---|
| 1360 | [TestMethod]
|
---|
[15857] | 1361 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1362 | [TestProperty("Time", "short")]
|
---|
[6846] | 1363 | public void TestHexadecimalPublicKeyToken() {
|
---|
| 1364 | string name = "TestClass, TestAssembly, Version=1.2.3.4, PublicKey=1234abc";
|
---|
| 1365 | string shortName = "TestClass, TestAssembly";
|
---|
| 1366 | Assert.AreEqual(name, TypeNameParser.Parse(name).ToString());
|
---|
| 1367 | Assert.AreEqual(shortName, TypeNameParser.Parse(name).ToString(false));
|
---|
| 1368 | }
|
---|
| 1369 |
|
---|
| 1370 | [TestMethod]
|
---|
[15857] | 1371 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1372 | [TestProperty("Time", "short")]
|
---|
[6846] | 1373 | public void InheritanceTest() {
|
---|
[13386] | 1374 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1375 | New n = new New();
|
---|
[13386] | 1376 | serializer.Serialize(n, tempFile);
|
---|
| 1377 | New nn = (New)serializer.Deserialize(tempFile);
|
---|
[6846] | 1378 | Assert.AreEqual(n.Name, nn.Name);
|
---|
| 1379 | Assert.AreEqual(((Override)n).Name, ((Override)nn).Name);
|
---|
| 1380 | }
|
---|
| 1381 |
|
---|
[14711] | 1382 | [StorableType("B963EF51-12B4-432E-8C54-88F026F9ACE2")]
|
---|
[6846] | 1383 | class Child {
|
---|
| 1384 | [Storable]
|
---|
| 1385 | public GrandParent grandParent;
|
---|
| 1386 | }
|
---|
| 1387 |
|
---|
[14711] | 1388 | [StorableType("E66E9606-967A-4C35-A361-F6F0D21C064A")]
|
---|
[6846] | 1389 | class Parent {
|
---|
| 1390 | [Storable]
|
---|
| 1391 | public Child child;
|
---|
| 1392 | }
|
---|
| 1393 |
|
---|
[14711] | 1394 | [StorableType("34D3893A-57AD-4F72-878B-81D6FA3F14A9")]
|
---|
[6846] | 1395 | class GrandParent {
|
---|
| 1396 | [Storable]
|
---|
| 1397 | public Parent parent;
|
---|
| 1398 | }
|
---|
| 1399 |
|
---|
| 1400 | [TestMethod]
|
---|
[15857] | 1401 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1402 | [TestProperty("Time", "short")]
|
---|
[6846] | 1403 | public void InstantiateParentChainReference() {
|
---|
[13386] | 1404 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1405 | GrandParent gp = new GrandParent();
|
---|
| 1406 | gp.parent = new Parent();
|
---|
| 1407 | gp.parent.child = new Child();
|
---|
| 1408 | gp.parent.child.grandParent = gp;
|
---|
| 1409 | Assert.AreSame(gp, gp.parent.child.grandParent);
|
---|
[13386] | 1410 | serializer.Serialize(gp, tempFile);
|
---|
| 1411 | GrandParent newGp = (GrandParent)serializer.Deserialize(tempFile);
|
---|
[6846] | 1412 | Assert.AreSame(newGp, newGp.parent.child.grandParent);
|
---|
| 1413 | }
|
---|
| 1414 |
|
---|
[14711] | 1415 | [StorableType("15DF777F-B12D-4FD4-88C3-8CB4C9CE4F0C")]
|
---|
[6846] | 1416 | struct TestStruct {
|
---|
| 1417 | int value;
|
---|
| 1418 | int PropertyValue { get; set; }
|
---|
| 1419 | public TestStruct(int value)
|
---|
| 1420 | : this() {
|
---|
| 1421 | this.value = value;
|
---|
| 1422 | PropertyValue = value;
|
---|
| 1423 | }
|
---|
| 1424 | }
|
---|
| 1425 |
|
---|
| 1426 | [TestMethod]
|
---|
[15857] | 1427 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1428 | [TestProperty("Time", "short")]
|
---|
[6846] | 1429 | public void StructTest() {
|
---|
[13386] | 1430 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1431 | TestStruct s = new TestStruct(10);
|
---|
[13386] | 1432 | serializer.Serialize(s, tempFile);
|
---|
| 1433 | TestStruct newS = (TestStruct)serializer.Deserialize(tempFile);
|
---|
[6846] | 1434 | Assert.AreEqual(s, newS);
|
---|
| 1435 | }
|
---|
| 1436 |
|
---|
| 1437 | [TestMethod]
|
---|
[15857] | 1438 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1439 | [TestProperty("Time", "short")]
|
---|
[6846] | 1440 | public void PointTest() {
|
---|
[13386] | 1441 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1442 | Point p = new Point(12, 34);
|
---|
[13386] | 1443 | serializer.Serialize(p, tempFile);
|
---|
| 1444 | Point newP = (Point)serializer.Deserialize(tempFile);
|
---|
[6846] | 1445 | Assert.AreEqual(p, newP);
|
---|
| 1446 | }
|
---|
| 1447 |
|
---|
| 1448 | [TestMethod]
|
---|
[15857] | 1449 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1450 | [TestProperty("Time", "short")]
|
---|
[6846] | 1451 | public void NullableValueTypes() {
|
---|
[13386] | 1452 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1453 | double?[] d = new double?[] { null, 1, 2, 3 };
|
---|
[13386] | 1454 | serializer.Serialize(d, tempFile);
|
---|
| 1455 | double?[] newD = (double?[])serializer.Deserialize(tempFile);
|
---|
[6846] | 1456 | Assert.AreEqual(d[0], newD[0]);
|
---|
| 1457 | Assert.AreEqual(d[1], newD[1]);
|
---|
| 1458 | Assert.AreEqual(d[2], newD[2]);
|
---|
| 1459 | Assert.AreEqual(d[3], newD[3]);
|
---|
| 1460 | }
|
---|
| 1461 |
|
---|
| 1462 | [TestMethod]
|
---|
[15857] | 1463 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1464 | [TestProperty("Time", "short")]
|
---|
[6846] | 1465 | public void BitmapTest() {
|
---|
[13386] | 1466 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1467 | Icon icon = System.Drawing.SystemIcons.Hand;
|
---|
| 1468 | Bitmap bitmap = icon.ToBitmap();
|
---|
[13386] | 1469 | serializer.Serialize(bitmap, tempFile);
|
---|
| 1470 | Bitmap newBitmap = (Bitmap)serializer.Deserialize(tempFile);
|
---|
[6846] | 1471 |
|
---|
| 1472 | Assert.AreEqual(bitmap.Size, newBitmap.Size);
|
---|
| 1473 | for (int i = 0; i < bitmap.Size.Width; i++)
|
---|
| 1474 | for (int j = 0; j < bitmap.Size.Height; j++)
|
---|
| 1475 | Assert.AreEqual(bitmap.GetPixel(i, j), newBitmap.GetPixel(i, j));
|
---|
| 1476 | }
|
---|
| 1477 |
|
---|
[14711] | 1478 | [StorableType("E846BC49-20F3-4D3F-A3F3-73D4F2DB1C2E")]
|
---|
[6846] | 1479 | private class PersistenceHooks {
|
---|
| 1480 | [Storable]
|
---|
| 1481 | public int a;
|
---|
| 1482 | [Storable]
|
---|
| 1483 | public int b;
|
---|
| 1484 | public int sum;
|
---|
| 1485 | public bool WasSerialized { get; private set; }
|
---|
| 1486 | [StorableHook(HookType.BeforeSerialization)]
|
---|
| 1487 | void PreSerializationHook() {
|
---|
| 1488 | WasSerialized = true;
|
---|
| 1489 | }
|
---|
| 1490 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 1491 | void PostDeserializationHook() {
|
---|
| 1492 | sum = a + b;
|
---|
| 1493 | }
|
---|
| 1494 | }
|
---|
| 1495 |
|
---|
| 1496 | [TestMethod]
|
---|
[15857] | 1497 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1498 | [TestProperty("Time", "short")]
|
---|
[6846] | 1499 | public void HookTest() {
|
---|
[13386] | 1500 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1501 | PersistenceHooks hookTest = new PersistenceHooks();
|
---|
| 1502 | hookTest.a = 2;
|
---|
| 1503 | hookTest.b = 5;
|
---|
| 1504 | Assert.IsFalse(hookTest.WasSerialized);
|
---|
| 1505 | Assert.AreEqual(hookTest.sum, 0);
|
---|
[13386] | 1506 | serializer.Serialize(hookTest, tempFile);
|
---|
[6846] | 1507 | Assert.IsTrue(hookTest.WasSerialized);
|
---|
| 1508 | Assert.AreEqual(hookTest.sum, 0);
|
---|
[13386] | 1509 | PersistenceHooks newHookTest = (PersistenceHooks)serializer.Deserialize(tempFile);
|
---|
[6846] | 1510 | Assert.AreEqual(newHookTest.a, hookTest.a);
|
---|
| 1511 | Assert.AreEqual(newHookTest.b, hookTest.b);
|
---|
| 1512 | Assert.AreEqual(newHookTest.sum, newHookTest.a + newHookTest.b);
|
---|
| 1513 | Assert.IsFalse(newHookTest.WasSerialized);
|
---|
| 1514 | }
|
---|
| 1515 |
|
---|
[14711] | 1516 | [StorableType("A35D71DF-397F-4910-A950-ED6923BE9483")]
|
---|
[6846] | 1517 | private class CustomConstructor {
|
---|
| 1518 | public string Value = "none";
|
---|
| 1519 | public CustomConstructor() {
|
---|
| 1520 | Value = "default";
|
---|
| 1521 | }
|
---|
| 1522 | [StorableConstructor]
|
---|
[15857] | 1523 | private CustomConstructor(StorableConstructorFlag _) {
|
---|
[6846] | 1524 | Value = "persistence";
|
---|
| 1525 | }
|
---|
| 1526 | }
|
---|
| 1527 |
|
---|
| 1528 | [TestMethod]
|
---|
[15857] | 1529 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1530 | [TestProperty("Time", "short")]
|
---|
[6846] | 1531 | public void TestCustomConstructor() {
|
---|
[13386] | 1532 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1533 | CustomConstructor cc = new CustomConstructor();
|
---|
| 1534 | Assert.AreEqual(cc.Value, "default");
|
---|
[13386] | 1535 | serializer.Serialize(cc, tempFile);
|
---|
| 1536 | CustomConstructor newCC = (CustomConstructor)serializer.Deserialize(tempFile);
|
---|
[6846] | 1537 | Assert.AreEqual(newCC.Value, "persistence");
|
---|
| 1538 | }
|
---|
| 1539 |
|
---|
[14711] | 1540 | [StorableType("D276E825-1F35-4BAC-8937-9ABC91D5C316")]
|
---|
[6846] | 1541 | public class ExplodingDefaultConstructor {
|
---|
| 1542 | public ExplodingDefaultConstructor() {
|
---|
| 1543 | throw new Exception("this constructor will always fail");
|
---|
| 1544 | }
|
---|
| 1545 | public ExplodingDefaultConstructor(string password) {
|
---|
| 1546 | }
|
---|
| 1547 | }
|
---|
| 1548 |
|
---|
| 1549 | [TestMethod]
|
---|
[15857] | 1550 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1551 | [TestProperty("Time", "short")]
|
---|
[6846] | 1552 | public void TestConstructorExceptionUnwrapping() {
|
---|
[13386] | 1553 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1554 | ExplodingDefaultConstructor x = new ExplodingDefaultConstructor("password");
|
---|
[13386] | 1555 | serializer.Serialize(x, tempFile);
|
---|
[6846] | 1556 | try {
|
---|
[13386] | 1557 | ExplodingDefaultConstructor newX = (ExplodingDefaultConstructor)serializer.Deserialize(tempFile);
|
---|
[6846] | 1558 | Assert.Fail("Exception expected");
|
---|
[14537] | 1559 | } catch (PersistenceException pe) {
|
---|
[6846] | 1560 | Assert.AreEqual(pe.InnerException.Message, "this constructor will always fail");
|
---|
| 1561 | }
|
---|
| 1562 | }
|
---|
| 1563 |
|
---|
| 1564 | [TestMethod]
|
---|
[15857] | 1565 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1566 | [TestProperty("Time", "short")]
|
---|
[6846] | 1567 | public void TestStreaming() {
|
---|
[13386] | 1568 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1569 | using (MemoryStream stream = new MemoryStream()) {
|
---|
| 1570 | Root r = InitializeComplexStorable();
|
---|
[13386] | 1571 | serializer.Serialize(r, stream);
|
---|
[6846] | 1572 | using (MemoryStream stream2 = new MemoryStream(stream.ToArray())) {
|
---|
[13386] | 1573 | Root newR = (Root)serializer.Deserialize(stream2);
|
---|
[6846] | 1574 | CompareComplexStorables(r, newR);
|
---|
| 1575 | }
|
---|
| 1576 | }
|
---|
| 1577 | }
|
---|
| 1578 |
|
---|
[14711] | 1579 | [StorableType("4921031B-CB61-4677-97AD-9236A4CEC200")]
|
---|
[6846] | 1580 | public class HookInheritanceTestBase {
|
---|
| 1581 | [Storable]
|
---|
| 1582 | public object a;
|
---|
| 1583 | public object link;
|
---|
| 1584 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 1585 | private void relink() {
|
---|
| 1586 | link = a;
|
---|
| 1587 | }
|
---|
| 1588 | }
|
---|
| 1589 |
|
---|
[14711] | 1590 | [StorableType("321CEE0A-5201-4CE2-B135-2343890D96BF")]
|
---|
[6846] | 1591 | public class HookInheritanceTestDerivedClass : HookInheritanceTestBase {
|
---|
| 1592 | [Storable]
|
---|
| 1593 | public object b;
|
---|
| 1594 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 1595 | private void relink() {
|
---|
| 1596 | Assert.AreSame(a, link);
|
---|
| 1597 | link = b;
|
---|
| 1598 | }
|
---|
| 1599 | }
|
---|
| 1600 |
|
---|
| 1601 | [TestMethod]
|
---|
[15857] | 1602 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1603 | [TestProperty("Time", "short")]
|
---|
[6846] | 1604 | public void TestLinkInheritance() {
|
---|
[13386] | 1605 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1606 | HookInheritanceTestDerivedClass c = new HookInheritanceTestDerivedClass();
|
---|
| 1607 | c.a = new object();
|
---|
[13386] | 1608 | serializer.Serialize(c, tempFile);
|
---|
| 1609 | HookInheritanceTestDerivedClass newC = (HookInheritanceTestDerivedClass)serializer.Deserialize(tempFile);
|
---|
[6846] | 1610 | Assert.AreSame(c.b, c.link);
|
---|
| 1611 | }
|
---|
| 1612 |
|
---|
[14711] | 1613 | [StorableType(StorableMemberSelection.AllFields, "B9AB42E8-1932-425B-B4CF-F31F07EAC599")]
|
---|
[6846] | 1614 | public class AllFieldsStorable {
|
---|
| 1615 | public int Value1 = 1;
|
---|
| 1616 | [Storable]
|
---|
| 1617 | public int Value2 = 2;
|
---|
| 1618 | public int Value3 { get; private set; }
|
---|
| 1619 | public int Value4 { get; private set; }
|
---|
| 1620 | [StorableConstructor]
|
---|
[15857] | 1621 | private AllFieldsStorable(StorableConstructorFlag _) { }
|
---|
| 1622 | public AllFieldsStorable() {
|
---|
[15020] | 1623 | Value1 = 12;
|
---|
| 1624 | Value2 = 23;
|
---|
| 1625 | Value3 = 34;
|
---|
| 1626 | Value4 = 56;
|
---|
| 1627 | }
|
---|
[6846] | 1628 | }
|
---|
| 1629 |
|
---|
| 1630 | [TestMethod]
|
---|
[15857] | 1631 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1632 | [TestProperty("Time", "short")]
|
---|
[14711] | 1633 | public void TestStorableTypeDiscoveryAllFields() {
|
---|
[13386] | 1634 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[15857] | 1635 | AllFieldsStorable afs = new AllFieldsStorable();
|
---|
[13386] | 1636 | serializer.Serialize(afs, tempFile);
|
---|
| 1637 | AllFieldsStorable newAfs = (AllFieldsStorable)serializer.Deserialize(tempFile);
|
---|
[6846] | 1638 | Assert.AreEqual(afs.Value1, newAfs.Value1);
|
---|
| 1639 | Assert.AreEqual(afs.Value2, newAfs.Value2);
|
---|
| 1640 | Assert.AreEqual(0, newAfs.Value3);
|
---|
| 1641 | Assert.AreEqual(0, newAfs.Value4);
|
---|
| 1642 | }
|
---|
| 1643 |
|
---|
[14711] | 1644 | [StorableType(StorableMemberSelection.AllProperties, "CB7DC31C-AEF3-4EB8-91CA-248B767E9F92")]
|
---|
[6846] | 1645 | public class AllPropertiesStorable {
|
---|
| 1646 | public int Value1 = 1;
|
---|
| 1647 | [Storable]
|
---|
| 1648 | public int Value2 = 2;
|
---|
| 1649 | public int Value3 { get; private set; }
|
---|
| 1650 | public int Value4 { get; private set; }
|
---|
[15020] | 1651 |
|
---|
[15857] | 1652 | [StorableConstructor]
|
---|
| 1653 | private AllPropertiesStorable(StorableConstructorFlag _) { }
|
---|
[15020] | 1654 | public AllPropertiesStorable() {
|
---|
| 1655 | Value1 = 12;
|
---|
| 1656 | Value2 = 23;
|
---|
| 1657 | Value3 = 34;
|
---|
| 1658 | Value4 = 56;
|
---|
| 1659 | }
|
---|
[6846] | 1660 | }
|
---|
| 1661 |
|
---|
| 1662 | [TestMethod]
|
---|
[15857] | 1663 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1664 | [TestProperty("Time", "short")]
|
---|
[14711] | 1665 | public void TestStorableTypeDiscoveryAllProperties() {
|
---|
[13386] | 1666 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[15020] | 1667 | AllPropertiesStorable afs = new AllPropertiesStorable();
|
---|
[13386] | 1668 | serializer.Serialize(afs, tempFile);
|
---|
| 1669 | AllPropertiesStorable newAfs = (AllPropertiesStorable)serializer.Deserialize(tempFile);
|
---|
[6846] | 1670 | Assert.AreEqual(1, newAfs.Value1);
|
---|
| 1671 | Assert.AreEqual(2, newAfs.Value2);
|
---|
| 1672 | Assert.AreEqual(afs.Value3, newAfs.Value3);
|
---|
| 1673 | Assert.AreEqual(afs.Value4, newAfs.Value4);
|
---|
| 1674 |
|
---|
| 1675 | }
|
---|
| 1676 |
|
---|
[14711] | 1677 | [StorableType(StorableMemberSelection.AllFieldsAndAllProperties, "0AD8D68F-E0FF-4FA8-8A72-1148CD91A2B9")]
|
---|
[6846] | 1678 | public class AllFieldsAndAllPropertiesStorable {
|
---|
| 1679 | public int Value1 = 1;
|
---|
| 1680 | [Storable]
|
---|
| 1681 | public int Value2 = 2;
|
---|
| 1682 | public int Value3 { get; private set; }
|
---|
| 1683 | public int Value4 { get; private set; }
|
---|
[15857] | 1684 | [StorableConstructor]
|
---|
| 1685 | private AllFieldsAndAllPropertiesStorable(StorableConstructorFlag _) { }
|
---|
[15020] | 1686 | public AllFieldsAndAllPropertiesStorable() {
|
---|
| 1687 | Value1 = 12;
|
---|
| 1688 | Value2 = 23;
|
---|
| 1689 | Value3 = 34;
|
---|
| 1690 | Value4 = 56;
|
---|
| 1691 | }
|
---|
[6846] | 1692 | }
|
---|
| 1693 |
|
---|
| 1694 | [TestMethod]
|
---|
[15857] | 1695 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1696 | [TestProperty("Time", "short")]
|
---|
[14711] | 1697 | public void TestStorableTypeDiscoveryAllFieldsAndAllProperties() {
|
---|
[13386] | 1698 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[15020] | 1699 | AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable();
|
---|
[13386] | 1700 | serializer.Serialize(afs, tempFile);
|
---|
| 1701 | AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)serializer.Deserialize(tempFile);
|
---|
[6846] | 1702 | Assert.AreEqual(afs.Value1, newAfs.Value1);
|
---|
| 1703 | Assert.AreEqual(afs.Value2, newAfs.Value2);
|
---|
| 1704 | Assert.AreEqual(afs.Value3, newAfs.Value3);
|
---|
| 1705 | Assert.AreEqual(afs.Value4, newAfs.Value4);
|
---|
| 1706 | }
|
---|
| 1707 |
|
---|
[14711] | 1708 | [StorableType(StorableMemberSelection.MarkedOnly, "0D94E6D4-64E3-4637-B1EE-DEF2B3F6E2E0")]
|
---|
[6846] | 1709 | public class MarkedOnlyStorable {
|
---|
| 1710 | public int Value1 = 1;
|
---|
| 1711 | [Storable]
|
---|
| 1712 | public int Value2 = 2;
|
---|
| 1713 | public int Value3 { get; private set; }
|
---|
| 1714 | public int Value4 { get; private set; }
|
---|
[15857] | 1715 | [StorableConstructor]
|
---|
| 1716 | private MarkedOnlyStorable(StorableConstructorFlag _) { }
|
---|
[15020] | 1717 | public MarkedOnlyStorable() {
|
---|
| 1718 | Value1 = 12;
|
---|
| 1719 | Value2 = 23;
|
---|
| 1720 | Value3 = 34;
|
---|
| 1721 | Value4 = 56;
|
---|
| 1722 | }
|
---|
[6846] | 1723 | }
|
---|
| 1724 |
|
---|
| 1725 | [TestMethod]
|
---|
[15857] | 1726 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1727 | [TestProperty("Time", "short")]
|
---|
[14711] | 1728 | public void TestStorableTypeDiscoveryMarkedOnly() {
|
---|
[13386] | 1729 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[15020] | 1730 | MarkedOnlyStorable afs = new MarkedOnlyStorable();
|
---|
[13386] | 1731 | serializer.Serialize(afs, tempFile);
|
---|
| 1732 | MarkedOnlyStorable newAfs = (MarkedOnlyStorable)serializer.Deserialize(tempFile);
|
---|
[6846] | 1733 | Assert.AreEqual(1, newAfs.Value1);
|
---|
| 1734 | Assert.AreEqual(afs.Value2, newAfs.Value2);
|
---|
| 1735 | Assert.AreEqual(0, newAfs.Value3);
|
---|
| 1736 | Assert.AreEqual(0, newAfs.Value4);
|
---|
| 1737 | }
|
---|
| 1738 |
|
---|
| 1739 | [TestMethod]
|
---|
[15857] | 1740 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1741 | [TestProperty("Time", "short")]
|
---|
[6846] | 1742 | public void TestLineEndings() {
|
---|
[13386] | 1743 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1744 | List<string> lineBreaks = new List<string> { "\r\n", "\n", "\r", "\n\r", Environment.NewLine };
|
---|
| 1745 | List<string> lines = new List<string>();
|
---|
| 1746 | foreach (var br in lineBreaks)
|
---|
| 1747 | lines.Add("line1" + br + "line2");
|
---|
[13386] | 1748 | serializer.Serialize(lines, tempFile);
|
---|
| 1749 | List<string> newLines = (List<string>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1750 | Assert.AreEqual(lines.Count, newLines.Count);
|
---|
| 1751 | for (int i = 0; i < lineBreaks.Count; i++) {
|
---|
| 1752 | Assert.AreEqual(lines[i], newLines[i]);
|
---|
| 1753 | }
|
---|
| 1754 | }
|
---|
| 1755 |
|
---|
| 1756 | [TestMethod]
|
---|
[15857] | 1757 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1758 | [TestProperty("Time", "short")]
|
---|
[6846] | 1759 | public void TestSpecialNumbers() {
|
---|
[13386] | 1760 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1761 | List<double> specials = new List<double>() { 1.0 / 0, -1.0 / 0, 0.0 / 0 };
|
---|
| 1762 | Assert.IsTrue(double.IsPositiveInfinity(specials[0]));
|
---|
| 1763 | Assert.IsTrue(double.IsNegativeInfinity(specials[1]));
|
---|
| 1764 | Assert.IsTrue(double.IsNaN(specials[2]));
|
---|
[13386] | 1765 | serializer.Serialize(specials, tempFile);
|
---|
| 1766 | List<double> newSpecials = (List<double>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1767 | Assert.IsTrue(double.IsPositiveInfinity(newSpecials[0]));
|
---|
| 1768 | Assert.IsTrue(double.IsNegativeInfinity(newSpecials[1]));
|
---|
| 1769 | Assert.IsTrue(double.IsNaN(newSpecials[2]));
|
---|
| 1770 | }
|
---|
| 1771 |
|
---|
| 1772 | [TestMethod]
|
---|
[15857] | 1773 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1774 | [TestProperty("Time", "short")]
|
---|
[6846] | 1775 | public void TestStringSplit() {
|
---|
| 1776 | string s = "1.2;2.3;3.4;;;4.9";
|
---|
| 1777 | var l = s.EnumerateSplit(';').ToList();
|
---|
| 1778 | Assert.AreEqual("1.2", l[0]);
|
---|
| 1779 | Assert.AreEqual("2.3", l[1]);
|
---|
| 1780 | Assert.AreEqual("3.4", l[2]);
|
---|
| 1781 | Assert.AreEqual("4.9", l[3]);
|
---|
| 1782 | }
|
---|
| 1783 |
|
---|
[14711] | 1784 | [StorableType("B13CB1B0-D2DA-47B8-A715-B166A28B1F03")]
|
---|
[6846] | 1785 | private class IdentityComparer<T> : IEqualityComparer<T> {
|
---|
| 1786 |
|
---|
| 1787 | public bool Equals(T x, T y) {
|
---|
| 1788 | return x.Equals(y);
|
---|
| 1789 | }
|
---|
| 1790 |
|
---|
| 1791 | public int GetHashCode(T obj) {
|
---|
| 1792 | return obj.GetHashCode();
|
---|
| 1793 | }
|
---|
| 1794 | }
|
---|
| 1795 |
|
---|
| 1796 | [TestMethod]
|
---|
[15857] | 1797 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1798 | [TestProperty("Time", "short")]
|
---|
[6846] | 1799 | public void TestHashSetSerializer() {
|
---|
[13386] | 1800 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1801 | var hashSets = new List<HashSet<int>>() {
|
---|
| 1802 | new HashSet<int>(new[] { 1, 2, 3 }),
|
---|
| 1803 | new HashSet<int>(new[] { 4, 5, 6 }, new IdentityComparer<int>()),
|
---|
| 1804 | };
|
---|
[13386] | 1805 | serializer.Serialize(hashSets, tempFile);
|
---|
| 1806 | var newHashSets = (List<HashSet<int>>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1807 | Assert.IsTrue(newHashSets[0].Contains(1));
|
---|
| 1808 | Assert.IsTrue(newHashSets[0].Contains(2));
|
---|
| 1809 | Assert.IsTrue(newHashSets[0].Contains(3));
|
---|
| 1810 | Assert.IsTrue(newHashSets[1].Contains(4));
|
---|
| 1811 | Assert.IsTrue(newHashSets[1].Contains(5));
|
---|
| 1812 | Assert.IsTrue(newHashSets[1].Contains(6));
|
---|
| 1813 | Assert.AreEqual(newHashSets[0].Comparer.GetType(), new HashSet<int>().Comparer.GetType());
|
---|
| 1814 | Assert.AreEqual(newHashSets[1].Comparer.GetType(), typeof(IdentityComparer<int>));
|
---|
| 1815 | }
|
---|
| 1816 |
|
---|
| 1817 | [TestMethod]
|
---|
[15857] | 1818 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1819 | [TestProperty("Time", "short")]
|
---|
[6846] | 1820 | public void TestConcreteDictionarySerializer() {
|
---|
[13386] | 1821 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1822 | var dictionaries = new List<Dictionary<int, int>>() {
|
---|
| 1823 | new Dictionary<int, int>(),
|
---|
| 1824 | new Dictionary<int, int>(new IdentityComparer<int>()),
|
---|
| 1825 | };
|
---|
| 1826 | dictionaries[0].Add(1, 1);
|
---|
| 1827 | dictionaries[0].Add(2, 2);
|
---|
| 1828 | dictionaries[0].Add(3, 3);
|
---|
| 1829 | dictionaries[1].Add(4, 4);
|
---|
| 1830 | dictionaries[1].Add(5, 5);
|
---|
| 1831 | dictionaries[1].Add(6, 6);
|
---|
[13386] | 1832 | serializer.Serialize(dictionaries, tempFile);
|
---|
| 1833 | var newDictionaries = (List<Dictionary<int, int>>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1834 | Assert.IsTrue(newDictionaries[0].ContainsKey(1));
|
---|
| 1835 | Assert.IsTrue(newDictionaries[0].ContainsKey(2));
|
---|
| 1836 | Assert.IsTrue(newDictionaries[0].ContainsKey(3));
|
---|
| 1837 | Assert.IsTrue(newDictionaries[1].ContainsKey(4));
|
---|
| 1838 | Assert.IsTrue(newDictionaries[1].ContainsKey(5));
|
---|
| 1839 | Assert.IsTrue(newDictionaries[1].ContainsKey(6));
|
---|
| 1840 | Assert.IsTrue(newDictionaries[0].ContainsValue(1));
|
---|
| 1841 | Assert.IsTrue(newDictionaries[0].ContainsValue(2));
|
---|
| 1842 | Assert.IsTrue(newDictionaries[0].ContainsValue(3));
|
---|
| 1843 | Assert.IsTrue(newDictionaries[1].ContainsValue(4));
|
---|
| 1844 | Assert.IsTrue(newDictionaries[1].ContainsValue(5));
|
---|
| 1845 | Assert.IsTrue(newDictionaries[1].ContainsValue(6));
|
---|
| 1846 | Assert.AreEqual(new Dictionary<int, int>().Comparer.GetType(), newDictionaries[0].Comparer.GetType());
|
---|
| 1847 | Assert.AreEqual(typeof(IdentityComparer<int>), newDictionaries[1].Comparer.GetType());
|
---|
| 1848 | }
|
---|
| 1849 |
|
---|
[14711] | 1850 | [StorableType("A9B0D7FB-0CAF-4DD7-9045-EA136F9176F7")]
|
---|
[6846] | 1851 | public class ReadOnlyFail {
|
---|
| 1852 | [Storable]
|
---|
| 1853 | public string ReadOnly {
|
---|
| 1854 | get { return "fail"; }
|
---|
| 1855 | }
|
---|
| 1856 | }
|
---|
| 1857 |
|
---|
| 1858 | [TestMethod]
|
---|
[15857] | 1859 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1860 | [TestProperty("Time", "short")]
|
---|
[6846] | 1861 | public void TestReadOnlyFail() {
|
---|
[13386] | 1862 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1863 | try {
|
---|
[13386] | 1864 | serializer.Serialize(new ReadOnlyFail(), tempFile);
|
---|
[6846] | 1865 | Assert.Fail("Exception expected");
|
---|
[14537] | 1866 | } catch (PersistenceException) {
|
---|
| 1867 | } catch {
|
---|
[6846] | 1868 | Assert.Fail("PersistenceException expected");
|
---|
| 1869 | }
|
---|
| 1870 | }
|
---|
| 1871 |
|
---|
| 1872 |
|
---|
[14711] | 1873 | [StorableType("2C9CC576-6823-4784-817B-37C8AF0B1C29")]
|
---|
[6846] | 1874 | public class WriteOnlyFail {
|
---|
| 1875 | [Storable]
|
---|
| 1876 | public string WriteOnly {
|
---|
| 1877 | set { throw new InvalidOperationException("this property should never be set."); }
|
---|
| 1878 | }
|
---|
| 1879 | }
|
---|
| 1880 |
|
---|
| 1881 | [TestMethod]
|
---|
[15857] | 1882 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1883 | [TestProperty("Time", "short")]
|
---|
[6846] | 1884 | public void TestWriteOnlyFail() {
|
---|
[13386] | 1885 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1886 | try {
|
---|
[13386] | 1887 | serializer.Serialize(new WriteOnlyFail(), tempFile);
|
---|
[6846] | 1888 | Assert.Fail("Exception expected");
|
---|
[14537] | 1889 | } catch (PersistenceException) {
|
---|
| 1890 | } catch {
|
---|
[6846] | 1891 | Assert.Fail("PersistenceException expected.");
|
---|
| 1892 | }
|
---|
| 1893 | }
|
---|
| 1894 |
|
---|
[15857] | 1895 | // TODO
|
---|
| 1896 | //[StorableType("8052D9E3-6DDD-4AE1-9B5B-67C6D5436512")]
|
---|
| 1897 | //public class OneWayTest {
|
---|
| 1898 | // public OneWayTest() { this.value = "default"; }
|
---|
| 1899 | // public string value;
|
---|
| 1900 | // [Storable(AllowOneWay = true)]
|
---|
| 1901 | // public string ReadOnly {
|
---|
| 1902 | // get { return "ReadOnly"; }
|
---|
| 1903 | // }
|
---|
| 1904 | // [Storable(AllowOneWay = true)]
|
---|
| 1905 | // public string WriteOnly {
|
---|
| 1906 | // set { this.value = value; }
|
---|
| 1907 | // }
|
---|
| 1908 | //}
|
---|
[6846] | 1909 |
|
---|
[15857] | 1910 | //[TestMethod]
|
---|
| 1911 | //[TestCategory("PersistenceNew")]
|
---|
| 1912 | //[TestProperty("Time", "short")]
|
---|
| 1913 | //public void TestTypeCacheExport() {
|
---|
| 1914 | // ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 1915 | // var test = new List<List<int>>();
|
---|
| 1916 | // test.Add(new List<int>() { 1, 2, 3 });
|
---|
| 1917 | // IEnumerable<Type> types;
|
---|
| 1918 | // using (var stream = new MemoryStream()) {
|
---|
| 1919 | // XmlGenerator.Serialize(test, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types);
|
---|
| 1920 | // }
|
---|
| 1921 | // List<Type> t = new List<Type>(types);
|
---|
| 1922 | // // Assert.IsTrue(t.Contains(typeof(int))); not serialized as an int list is directly transformed into a string
|
---|
| 1923 | // Assert.IsTrue(t.Contains(typeof(List<int>)));
|
---|
| 1924 | // Assert.IsTrue(t.Contains(typeof(List<List<int>>)));
|
---|
| 1925 | // Assert.AreEqual(t.Count, 2);
|
---|
| 1926 | //}
|
---|
[6846] | 1927 |
|
---|
| 1928 | [TestMethod]
|
---|
[15857] | 1929 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1930 | [TestProperty("Time", "short")]
|
---|
[6846] | 1931 | public void TupleTest() {
|
---|
| 1932 | var t1 = Tuple.Create(1);
|
---|
| 1933 | var t2 = Tuple.Create('1', "2");
|
---|
| 1934 | var t3 = Tuple.Create(3.0, 3f, 5);
|
---|
| 1935 | var t4 = Tuple.Create(Tuple.Create(1, 2, 3), Tuple.Create(4, 5, 6), Tuple.Create(8, 9, 10));
|
---|
| 1936 | var tuple = Tuple.Create(t1, t2, t3, t4);
|
---|
[14537] | 1937 | SerializeNew(tuple);
|
---|
| 1938 | var newTuple = DeserializeNew();
|
---|
[6846] | 1939 | Assert.AreEqual(tuple, newTuple);
|
---|
| 1940 | }
|
---|
| 1941 |
|
---|
| 1942 | [TestMethod]
|
---|
[15857] | 1943 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1944 | [TestProperty("Time", "short")]
|
---|
[6846] | 1945 | public void FontTest() {
|
---|
[13386] | 1946 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1947 | List<Font> fonts = new List<Font>() {
|
---|
| 1948 | new Font(FontFamily.GenericSansSerif, 12),
|
---|
| 1949 | new Font("Times New Roman", 21, FontStyle.Bold, GraphicsUnit.Pixel),
|
---|
| 1950 | new Font("Courier New", 10, FontStyle.Underline, GraphicsUnit.Document),
|
---|
| 1951 | new Font("Helvetica", 21, FontStyle.Strikeout, GraphicsUnit.Inch, 0, true),
|
---|
| 1952 | };
|
---|
[13386] | 1953 | serializer.Serialize(fonts, tempFile);
|
---|
| 1954 | var newFonts = (List<Font>)serializer.Deserialize(tempFile);
|
---|
[6846] | 1955 | Assert.AreEqual(fonts[0], newFonts[0]);
|
---|
| 1956 | Assert.AreEqual(fonts[1], newFonts[1]);
|
---|
| 1957 | Assert.AreEqual(fonts[2], newFonts[2]);
|
---|
| 1958 | Assert.AreEqual(fonts[3], newFonts[3]);
|
---|
| 1959 | }
|
---|
| 1960 |
|
---|
| 1961 | [TestMethod]
|
---|
[15857] | 1962 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1963 | [TestProperty("Time", "medium")]
|
---|
[6846] | 1964 | public void ConcurrencyTest() {
|
---|
[13386] | 1965 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1966 | int n = 20;
|
---|
| 1967 | Task[] tasks = new Task[n];
|
---|
| 1968 | for (int i = 0; i < n; i++) {
|
---|
| 1969 | tasks[i] = Task.Factory.StartNew((idx) => {
|
---|
| 1970 | byte[] data;
|
---|
| 1971 | using (var stream = new MemoryStream()) {
|
---|
[13386] | 1972 | serializer.Serialize(new GeneticAlgorithm(), stream);
|
---|
[6846] | 1973 | data = stream.ToArray();
|
---|
| 1974 | }
|
---|
| 1975 | }, i);
|
---|
| 1976 | }
|
---|
| 1977 | Task.WaitAll(tasks);
|
---|
| 1978 | }
|
---|
| 1979 |
|
---|
| 1980 | [TestMethod]
|
---|
[15857] | 1981 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 1982 | [TestProperty("Time", "medium")]
|
---|
[6846] | 1983 | public void ConcurrentBitmapTest() {
|
---|
[13386] | 1984 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[6846] | 1985 | Bitmap b = new Bitmap(300, 300);
|
---|
| 1986 | System.Random r = new System.Random();
|
---|
| 1987 | for (int x = 0; x < b.Height; x++) {
|
---|
| 1988 | for (int y = 0; y < b.Width; y++) {
|
---|
| 1989 | b.SetPixel(x, y, Color.FromArgb(r.Next()));
|
---|
| 1990 | }
|
---|
| 1991 | }
|
---|
| 1992 | Task[] tasks = new Task[20];
|
---|
| 1993 | byte[][] datas = new byte[tasks.Length][];
|
---|
| 1994 | for (int i = 0; i < tasks.Length; i++) {
|
---|
| 1995 | tasks[i] = Task.Factory.StartNew((idx) => {
|
---|
| 1996 | using (var stream = new MemoryStream()) {
|
---|
[13386] | 1997 | serializer.Serialize(b, stream);
|
---|
[6846] | 1998 | datas[(int)idx] = stream.ToArray();
|
---|
| 1999 | }
|
---|
| 2000 | }, i);
|
---|
| 2001 | }
|
---|
| 2002 | Task.WaitAll(tasks);
|
---|
| 2003 | }
|
---|
| 2004 |
|
---|
[14928] | 2005 | [StorableType("4b4f6317-30c9-4ccd-ad5f-01775f728fbc")]
|
---|
[9778] | 2006 | public class G<T, T2> {
|
---|
[14928] | 2007 | [StorableType("dad331ad-dfc5-4ea5-b044-3e582fcc648d")]
|
---|
[9778] | 2008 | public class S { }
|
---|
[14928] | 2009 | [StorableType("171d3a18-d0ce-498a-a85f-7107a8a198ef")]
|
---|
[9778] | 2010 | public class S2<T3, T4> { }
|
---|
[9005] | 2011 | }
|
---|
| 2012 |
|
---|
| 2013 | [TestMethod]
|
---|
[15857] | 2014 | [TestCategory("PersistenceNew")]
|
---|
[9778] | 2015 | [TestProperty("Time", "short")]
|
---|
[10895] | 2016 | public void TestSpecialCharacters() {
|
---|
[13386] | 2017 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[10895] | 2018 | var s = "abc" + "\x15" + "def";
|
---|
[13386] | 2019 | serializer.Serialize(s, tempFile);
|
---|
| 2020 | var newS = serializer.Deserialize(tempFile);
|
---|
[10895] | 2021 | Assert.AreEqual(s, newS);
|
---|
| 2022 | }
|
---|
| 2023 |
|
---|
| 2024 | [TestMethod]
|
---|
[15857] | 2025 | [TestCategory("PersistenceNew")]
|
---|
[10895] | 2026 | [TestProperty("Time", "short")]
|
---|
| 2027 | public void TestByteArray() {
|
---|
[13386] | 2028 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[10895] | 2029 | var b = new byte[3];
|
---|
| 2030 | b[0] = 0;
|
---|
| 2031 | b[1] = 200;
|
---|
| 2032 | b[2] = byte.MaxValue;
|
---|
[13386] | 2033 | serializer.Serialize(b, tempFile);
|
---|
| 2034 | var newB = (byte[])serializer.Deserialize(tempFile);
|
---|
[10895] | 2035 | CollectionAssert.AreEqual(b, newB);
|
---|
| 2036 | }
|
---|
| 2037 |
|
---|
[10896] | 2038 | [TestMethod]
|
---|
[15857] | 2039 | [TestCategory("PersistenceNew")]
|
---|
[10896] | 2040 | [TestProperty("Time", "short")]
|
---|
| 2041 | public void TestOptionalNumberEnumerable() {
|
---|
[13386] | 2042 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13370] | 2043 | var values = new List<double?> { 0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1 };
|
---|
[13386] | 2044 | serializer.Serialize(values, tempFile);
|
---|
| 2045 | var newValues = (List<double?>)serializer.Deserialize(tempFile);
|
---|
[10896] | 2046 | CollectionAssert.AreEqual(values, newValues);
|
---|
| 2047 | }
|
---|
[10895] | 2048 |
|
---|
[11352] | 2049 | [TestMethod]
|
---|
[15857] | 2050 | [TestCategory("PersistenceNew")]
|
---|
[11352] | 2051 | [TestProperty("Time", "short")]
|
---|
| 2052 | public void TestOptionalDateTimeEnumerable() {
|
---|
[13386] | 2053 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[11352] | 2054 | var values = new List<DateTime?> { DateTime.MinValue, null, DateTime.Now, DateTime.Now.Add(TimeSpan.FromDays(1)),
|
---|
| 2055 | DateTime.ParseExact("10.09.2014 12:21", "dd.MM.yyyy hh:mm", CultureInfo.InvariantCulture), DateTime.MaxValue};
|
---|
[13386] | 2056 | serializer.Serialize(values, tempFile);
|
---|
| 2057 | var newValues = (List<DateTime?>)serializer.Deserialize(tempFile);
|
---|
[11352] | 2058 | CollectionAssert.AreEqual(values, newValues);
|
---|
| 2059 | }
|
---|
[10896] | 2060 |
|
---|
[11352] | 2061 | [TestMethod]
|
---|
[15857] | 2062 | [TestCategory("PersistenceNew")]
|
---|
[11352] | 2063 | [TestProperty("Time", "short")]
|
---|
| 2064 | public void TestStringEnumerable() {
|
---|
[13386] | 2065 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13370] | 2066 | var values = new List<string> { "", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated" };
|
---|
[13386] | 2067 | serializer.Serialize(values, tempFile);
|
---|
| 2068 | var newValues = (List<String>)serializer.Deserialize(tempFile);
|
---|
[11352] | 2069 | CollectionAssert.AreEqual(values, newValues);
|
---|
| 2070 | }
|
---|
| 2071 |
|
---|
| 2072 | [TestMethod]
|
---|
[15857] | 2073 | [TestCategory("PersistenceNew")]
|
---|
[11352] | 2074 | [TestProperty("Time", "short")]
|
---|
| 2075 | public void TestUnicodeCharArray() {
|
---|
[13386] | 2076 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13370] | 2077 | var s = Encoding.UTF8.GetChars(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb });
|
---|
[13386] | 2078 | serializer.Serialize(s, tempFile);
|
---|
| 2079 | var newS = (char[])serializer.Deserialize(tempFile);
|
---|
[11352] | 2080 | CollectionAssert.AreEqual(s, newS);
|
---|
| 2081 | }
|
---|
| 2082 |
|
---|
| 2083 | [TestMethod]
|
---|
[15857] | 2084 | [TestCategory("PersistenceNew")]
|
---|
[11352] | 2085 | [TestProperty("Time", "short")]
|
---|
| 2086 | public void TestUnicode() {
|
---|
[13386] | 2087 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13370] | 2088 | var s = Encoding.UTF8.GetString(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb });
|
---|
[13386] | 2089 | serializer.Serialize(s, tempFile);
|
---|
| 2090 | var newS = serializer.Deserialize(tempFile);
|
---|
[11352] | 2091 | Assert.AreEqual(s, newS);
|
---|
| 2092 | }
|
---|
| 2093 |
|
---|
[11353] | 2094 | [TestMethod]
|
---|
[15857] | 2095 | [TestCategory("PersistenceNew")]
|
---|
[11353] | 2096 | [TestProperty("Time", "short")]
|
---|
| 2097 | public void TestQueue() {
|
---|
[13386] | 2098 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[13370] | 2099 | var q = new Queue<int>(new[] { 1, 2, 3, 4, 0 });
|
---|
[13386] | 2100 | serializer.Serialize(q, tempFile);
|
---|
| 2101 | var newQ = (Queue<int>)serializer.Deserialize(tempFile);
|
---|
[11353] | 2102 | CollectionAssert.AreEqual(q, newQ);
|
---|
| 2103 | }
|
---|
[13386] | 2104 | #endregion
|
---|
[14549] | 2105 |
|
---|
[15857] | 2106 | #region New Persistence Tests
|
---|
[14711] | 2107 | [StorableType("6075F1E8-948A-4AD8-8F5A-942B777852EC")]
|
---|
[14549] | 2108 | public class A {
|
---|
| 2109 | [Storable]
|
---|
[14594] | 2110 | public B B { get; set; }
|
---|
| 2111 |
|
---|
[14711] | 2112 | [Storable]
|
---|
| 2113 | public int i;
|
---|
[14549] | 2114 | }
|
---|
[14711] | 2115 | [StorableType("287BFEA0-6E27-4839-BCEF-D134FE738AC8")]
|
---|
[14549] | 2116 | public class B {
|
---|
| 2117 | [Storable]
|
---|
| 2118 | public A A { get; set; }
|
---|
[14594] | 2119 |
|
---|
| 2120 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 2121 | void PostDeserializationHook() {
|
---|
| 2122 | //Assert.AreEqual(3, A.i);
|
---|
| 2123 | }
|
---|
[14549] | 2124 | }
|
---|
| 2125 |
|
---|
| 2126 | [TestMethod]
|
---|
[15857] | 2127 | [TestCategory("PersistenceNew")]
|
---|
[14549] | 2128 | [TestProperty("Time", "short")]
|
---|
| 2129 | public void TestCyclicReferencesWithTuple() {
|
---|
| 2130 | var test = new Func<A>(() => {
|
---|
[14594] | 2131 | var a = new A { i = 4 };
|
---|
[14549] | 2132 | var b = new B { A = a };
|
---|
[14594] | 2133 | a.B = b;
|
---|
[14549] | 2134 | return a;
|
---|
| 2135 | });
|
---|
| 2136 |
|
---|
[14594] | 2137 | //ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 2138 | //serializer.Serialize(test(), tempFile);
|
---|
| 2139 | //object o = serializer.Deserialize(tempFile);
|
---|
| 2140 | //A result = (A)o;
|
---|
[14549] | 2141 |
|
---|
[14594] | 2142 | XmlGenerator.Serialize(test(), tempFile);
|
---|
| 2143 | object o = XmlParser.Deserialize(tempFile);
|
---|
| 2144 |
|
---|
[14549] | 2145 | string msg = Profile(test);
|
---|
| 2146 | Console.WriteLine(msg);
|
---|
| 2147 | }
|
---|
[14594] | 2148 |
|
---|
[14739] | 2149 |
|
---|
| 2150 | #region conversion
|
---|
| 2151 |
|
---|
[14771] | 2152 | [StorableType("F9F51075-490C-48E3-BF64-14514A210149", 1)]
|
---|
[14739] | 2153 | private class OldBaseType {
|
---|
| 2154 | [Storable]
|
---|
| 2155 | public ItemCollection<IItem> items;
|
---|
| 2156 | }
|
---|
[14771] | 2157 | [StorableType("D211A828-6440-4E72-A8C7-AA4F9B4FFA75", 1)]
|
---|
| 2158 | private class V1 : OldBaseType {
|
---|
[14739] | 2159 | [Storable]
|
---|
| 2160 | public IntValue a;
|
---|
| 2161 |
|
---|
| 2162 | [Storable]
|
---|
| 2163 | public ItemList<IntValue> vals;
|
---|
| 2164 |
|
---|
| 2165 | [Storable]
|
---|
[14771] | 2166 | public V1 mySelf;
|
---|
[14739] | 2167 |
|
---|
| 2168 | [Storable]
|
---|
| 2169 | public Tuple<int, int> tup;
|
---|
| 2170 |
|
---|
| 2171 | [Storable]
|
---|
| 2172 | public int x;
|
---|
| 2173 | [Storable]
|
---|
| 2174 | public int y;
|
---|
[15035] | 2175 |
|
---|
| 2176 | [Storable]
|
---|
| 2177 | public string s;
|
---|
[14739] | 2178 | }
|
---|
| 2179 |
|
---|
| 2180 |
|
---|
[15529] | 2181 | [StorableType("B72C58C8-3321-4706-AA94-578F57337070")]
|
---|
[14739] | 2182 | private class NewBaseType {
|
---|
| 2183 | [Storable]
|
---|
| 2184 | public DoubleValue[] items;
|
---|
| 2185 | }
|
---|
[15529] | 2186 | [StorableType("00000000-0000-0000-0000-BADCAFFEE001", 2)] // for testing (version 2)
|
---|
[15034] | 2187 | private class V2 : NewBaseType {
|
---|
[14739] | 2188 | [Storable]
|
---|
| 2189 | public int a;
|
---|
| 2190 |
|
---|
| 2191 | [Storable]
|
---|
| 2192 | public int[] val;
|
---|
| 2193 |
|
---|
| 2194 | [Storable]
|
---|
[14771] | 2195 | public V2 mySelf;
|
---|
[14739] | 2196 |
|
---|
| 2197 | [Storable]
|
---|
| 2198 | public int TupItem1;
|
---|
| 2199 |
|
---|
| 2200 | [Storable]
|
---|
| 2201 | public int TupItem2;
|
---|
| 2202 |
|
---|
| 2203 | [Storable]
|
---|
| 2204 | public Point coords;
|
---|
[15035] | 2205 |
|
---|
| 2206 | [Storable(Name = "s")]
|
---|
| 2207 | public string StorableString { get; set; }
|
---|
[14739] | 2208 | }
|
---|
| 2209 |
|
---|
[15529] | 2210 | [StorableType("00000000-0000-0000-0000-BADCAFFEE002", 3)] // for testing (version 3)
|
---|
[15034] | 2211 | private class V3 : NewBaseType {
|
---|
[14771] | 2212 | [Storable]
|
---|
| 2213 | public int a;
|
---|
[14739] | 2214 |
|
---|
[14771] | 2215 | [Storable]
|
---|
| 2216 | public int[] val;
|
---|
[14739] | 2217 |
|
---|
[14771] | 2218 | [Storable]
|
---|
| 2219 | public V3 mySelf;
|
---|
| 2220 |
|
---|
| 2221 | [Storable]
|
---|
| 2222 | public Tuple<int, int> tup;
|
---|
| 2223 |
|
---|
| 2224 | [Storable]
|
---|
| 2225 | public Point coords;
|
---|
[15035] | 2226 |
|
---|
| 2227 | [Storable(Name = "s", AllowOneWay = true)]
|
---|
[15509] | 2228 | public string StorableString { set { PublicString = value; } }
|
---|
[15035] | 2229 | public string PublicString { get; set; }
|
---|
[14739] | 2230 | }
|
---|
| 2231 |
|
---|
[15034] | 2232 | private static class Conversions {
|
---|
| 2233 | [StorableConversion("D211A828-6440-4E72-A8C7-AA4F9B4FFA75", 1)]
|
---|
[14771] | 2234 | private static Dictionary<string, object> ConvertV1(Dictionary<string, object> values) {
|
---|
| 2235 | var newValues = new Dictionary<string, object>();
|
---|
[15529] | 2236 | var items = (ItemCollection<IItem>)values["F9F51075-490C-48E3-BF64-14514A210149.items"];
|
---|
| 2237 | newValues["B72C58C8-3321-4706-AA94-578F57337070.items"] = items.Select(iv => new DoubleValue((double)(((dynamic)iv).Value))).ToArray();
|
---|
| 2238 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.a"] = ((IntValue)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.a"]).Value;
|
---|
| 2239 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.val"] = ((ItemList<IntValue>)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.vals"]).Select(iv => iv.Value).ToArray();
|
---|
[14771] | 2240 |
|
---|
[15529] | 2241 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.mySelf"] = values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.mySelf"]; // myself type will be mapped correctly
|
---|
[14771] | 2242 |
|
---|
[15529] | 2243 | var tup = (Tuple<int, int>)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.tup"];
|
---|
[14771] | 2244 | if (tup != null) {
|
---|
[15529] | 2245 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.TupItem1"] = tup.Item1;
|
---|
| 2246 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.TupItem2"] = tup.Item2;
|
---|
[14771] | 2247 | }
|
---|
| 2248 |
|
---|
[15529] | 2249 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.coords"] = new Point((int)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.x"], (int)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.y"]);
|
---|
[14771] | 2250 |
|
---|
| 2251 | return newValues;
|
---|
| 2252 | }
|
---|
| 2253 |
|
---|
[15034] | 2254 | [StorableConversion("D211A828-6440-4E72-A8C7-AA4F9B4FFA75", 2)]
|
---|
[14771] | 2255 | private static Dictionary<string, object> ConvertV2(Dictionary<string, object> values) {
|
---|
| 2256 | var newValues = new Dictionary<string, object>();
|
---|
[15529] | 2257 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.a"] = values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.a"];
|
---|
| 2258 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.val"] = values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.val"];
|
---|
| 2259 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.mySelf"] = values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.mySelf"];
|
---|
[14771] | 2260 |
|
---|
[15529] | 2261 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.tup"] = Tuple.Create((int)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.TupItem1"], (int)values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.TupItem2"]);
|
---|
| 2262 | newValues["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.coords"] = values["D211A828-6440-4E72-A8C7-AA4F9B4FFA75.coords"];
|
---|
[14771] | 2263 |
|
---|
| 2264 | return newValues;
|
---|
| 2265 | }
|
---|
| 2266 | }
|
---|
| 2267 |
|
---|
[14594] | 2268 | [TestMethod]
|
---|
[15857] | 2269 | [TestCategory("PersistenceNew")]
|
---|
[14594] | 2270 | [TestProperty("Time", "short")]
|
---|
[14739] | 2271 | public void TestConversion() {
|
---|
[14771] | 2272 | var test = new Func<V1>(() => {
|
---|
| 2273 | var p = new V1();
|
---|
[14739] | 2274 | p.a = new IntValue(1);
|
---|
| 2275 | p.mySelf = p;
|
---|
| 2276 | p.vals = new ItemList<IntValue>(new IntValue[] { p.a, new IntValue(2), new IntValue(3) });
|
---|
[14771] | 2277 | p.tup = Tuple.Create(17, 4);
|
---|
[14739] | 2278 | var dv = new DoubleValue(1.0);
|
---|
| 2279 | p.items = new ItemCollection<IItem>(new IItem[] { dv, dv, p.a });
|
---|
[15035] | 2280 | p.s = "123";
|
---|
[14739] | 2281 | return p;
|
---|
| 2282 | });
|
---|
| 2283 |
|
---|
| 2284 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 2285 | var old = test();
|
---|
| 2286 | serializer.Serialize(old, tempFile);
|
---|
[14771] | 2287 |
|
---|
[15857] | 2288 | DeregisterType(typeof(V1));
|
---|
| 2289 | DeregisterType(typeof(V2));
|
---|
| 2290 | DeregisterType(typeof(V3));
|
---|
[15529] | 2291 |
|
---|
[15857] | 2292 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid, typeof(V3));
|
---|
| 2293 | SetTypeGuid(typeof(V3), GetTypeGuid(typeof(V1)));
|
---|
| 2294 | RemoveTypeInfo(typeof(V1));
|
---|
[15529] | 2295 |
|
---|
[14771] | 2296 | object o = serializer.Deserialize(tempFile);
|
---|
| 2297 | var restored = (V3)o;
|
---|
[15034] | 2298 | Assert.AreEqual(restored.a, old.a.Value);
|
---|
[15509] | 2299 | Assert.IsTrue(restored.val.SequenceEqual(old.vals.Select(iv => iv.Value)));
|
---|
[14771] | 2300 | Assert.IsTrue(restored.items.Select(item => item.Value).SequenceEqual(old.items.Select(iv => (double)((dynamic)iv).Value)));
|
---|
| 2301 | // Assert.AreSame(restored.items[0], restored.items[1]);
|
---|
| 2302 | Assert.AreSame(restored, restored.mySelf);
|
---|
[15035] | 2303 | Assert.AreEqual(restored.PublicString, old.s);
|
---|
[14771] | 2304 | }
|
---|
| 2305 |
|
---|
| 2306 | #endregion
|
---|
| 2307 |
|
---|
[14739] | 2308 | [TestMethod]
|
---|
[15857] | 2309 | [TestCategory("PersistenceNew")]
|
---|
[14739] | 2310 | [TestProperty("Time", "short")]
|
---|
[14594] | 2311 | public void TestGASerializeDeserializeExecute() {
|
---|
| 2312 | var test = new Func<GeneticAlgorithm>(() => {
|
---|
| 2313 | var ga = new GeneticAlgorithm();
|
---|
| 2314 | ga.Problem = new SingleObjectiveTestFunctionProblem();
|
---|
| 2315 | ga.MaximumGenerations.Value = 100;
|
---|
| 2316 | ga.SetSeedRandomly.Value = false;
|
---|
| 2317 | return ga;
|
---|
| 2318 | });
|
---|
| 2319 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[14932] | 2320 | GeneticAlgorithm original = test();
|
---|
| 2321 | serializer.Serialize(original, tempFile);
|
---|
[14594] | 2322 | object o = serializer.Deserialize(tempFile);
|
---|
[14932] | 2323 |
|
---|
| 2324 | // this fails because old persistence didn't handle all IComparer ?
|
---|
| 2325 | // Assert.AreEqual(DebugStringGenerator.Serialize(original),DebugStringGenerator.Serialize(o));
|
---|
| 2326 |
|
---|
[14594] | 2327 | GeneticAlgorithm result = (GeneticAlgorithm)o;
|
---|
| 2328 | SamplesUtils.RunAlgorithm(result);
|
---|
| 2329 | SamplesUtils.RunAlgorithm(original);
|
---|
[14932] | 2330 | Assert.AreEqual(((DoubleValue)result.Results["BestQuality"].Value).Value,
|
---|
| 2331 | ((DoubleValue)original.Results["BestQuality"].Value).Value);
|
---|
[14594] | 2332 |
|
---|
[14932] | 2333 | // Assert.AreEqual(DebugStringGenerator.Serialize(result), DebugStringGenerator.Serialize(result2));
|
---|
[14594] | 2334 | }
|
---|
[14932] | 2335 |
|
---|
[14594] | 2336 | [TestMethod]
|
---|
[15857] | 2337 | [TestCategory("PersistenceNew")]
|
---|
[14594] | 2338 | [TestProperty("Time", "short")]
|
---|
| 2339 | public void TestLoadingSamples() {
|
---|
[15509] | 2340 | var path = @"D:\Dev\Software_HL\branches\PersistenceReintegration\HeuristicLab.Optimizer\3.3\Documents";
|
---|
[14594] | 2341 | var serializer = new ProtoBufSerializer();
|
---|
| 2342 | foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) {
|
---|
| 2343 | var original = XmlParser.Deserialize(fileName);
|
---|
[14713] | 2344 | var ok = true;
|
---|
[14714] | 2345 | // foreach (var t in original.GetObjectGraphObjects().Select(o => o.GetType())) {
|
---|
| 2346 | // if (
|
---|
| 2347 | // t.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
|
---|
| 2348 | // .Any(ctor => StorableConstructorAttribute.IsStorableConstructor(ctor))) {
|
---|
| 2349 | // try {
|
---|
| 2350 | // if (t.IsGenericType) {
|
---|
| 2351 | // var g = Mapper.StaticCache.GetGuid(t.GetGenericTypeDefinition());
|
---|
| 2352 | // } else {
|
---|
| 2353 | // var g = Mapper.StaticCache.GetGuid(t);
|
---|
| 2354 | // }
|
---|
| 2355 | // } catch (Exception e) {
|
---|
| 2356 | // Console.WriteLine(t.FullName);
|
---|
| 2357 | // ok = false;
|
---|
| 2358 | // }
|
---|
| 2359 | // }
|
---|
| 2360 | // }
|
---|
[14713] | 2361 | if (ok) {
|
---|
| 2362 | serializer.Serialize(original, fileName + ".proto");
|
---|
| 2363 | // var newVersion = serializer.Deserialize(fileName + ".proto");
|
---|
[15529] | 2364 | //Console.WriteLine("File: " + fileName);
|
---|
| 2365 | var p = Profile(() => original, Path.GetFileName(fileName));
|
---|
[14713] | 2366 | Console.WriteLine(p);
|
---|
| 2367 | }
|
---|
[14594] | 2368 | }
|
---|
| 2369 | }
|
---|
[15529] | 2370 |
|
---|
| 2371 | [StorableType("3B48A44F-93E2-4ECC-A9B9-56E425EF96F8")]
|
---|
| 2372 | private class ConversionA {
|
---|
| 2373 | [Storable]
|
---|
| 2374 | public int f;
|
---|
| 2375 | }
|
---|
| 2376 |
|
---|
| 2377 | [StorableType("00000000-0000-0000-0000-000000000002", 2)]
|
---|
| 2378 | private class ConversionANew {
|
---|
| 2379 | [Storable]
|
---|
| 2380 | public int g;
|
---|
| 2381 | }
|
---|
| 2382 |
|
---|
| 2383 | [StorableType("7CBF2251-CF9F-4D9E-AA7B-C65495AE078F")]
|
---|
| 2384 | private class ConversionB : ConversionA {
|
---|
| 2385 | [Storable]
|
---|
| 2386 | public int f;
|
---|
| 2387 | public int BaseF { get { return base.f; } }
|
---|
| 2388 |
|
---|
| 2389 | public ConversionB() {
|
---|
| 2390 |
|
---|
| 2391 | }
|
---|
| 2392 |
|
---|
| 2393 | public ConversionB(int myF, int baseF) {
|
---|
| 2394 | this.f = myF;
|
---|
| 2395 | base.f = baseF;
|
---|
| 2396 | }
|
---|
| 2397 | }
|
---|
| 2398 |
|
---|
| 2399 | [StorableType("00000000-0000-0000-0000-000000000001", 2)]
|
---|
| 2400 | private class ConversionBNew : ConversionANew {
|
---|
| 2401 | [Storable]
|
---|
| 2402 | public int g;
|
---|
| 2403 |
|
---|
| 2404 | public int BaseG { get { return base.g; } }
|
---|
| 2405 | }
|
---|
| 2406 |
|
---|
| 2407 | private static class NewConversions {
|
---|
| 2408 | [StorableConversion("7CBF2251-CF9F-4D9E-AA7B-C65495AE078F", 1)]
|
---|
| 2409 | private static Dictionary<string, object> ConvertB(Dictionary<string, object> values) {
|
---|
| 2410 | var newValues = new Dictionary<string, object>();
|
---|
| 2411 | newValues["7CBF2251-CF9F-4D9E-AA7B-C65495AE078F.g"] = values["7CBF2251-CF9F-4D9E-AA7B-C65495AE078F.f"];
|
---|
| 2412 | return newValues;
|
---|
| 2413 | }
|
---|
| 2414 |
|
---|
| 2415 | [StorableConversion("3B48A44F-93E2-4ECC-A9B9-56E425EF96F8", 1)]
|
---|
| 2416 | private static Dictionary<string, object> ConvertA(Dictionary<string, object> values) {
|
---|
| 2417 | var newValues = new Dictionary<string, object>();
|
---|
| 2418 | newValues["3B48A44F-93E2-4ECC-A9B9-56E425EF96F8.g"] = values["3B48A44F-93E2-4ECC-A9B9-56E425EF96F8.f"];
|
---|
| 2419 | return newValues;
|
---|
| 2420 | }
|
---|
| 2421 | }
|
---|
| 2422 |
|
---|
| 2423 | [TestMethod]
|
---|
[15857] | 2424 | [TestCategory("PersistenceNew")]
|
---|
[15529] | 2425 | [TestProperty("Time", "short")]
|
---|
| 2426 | public void TestConversionCase1() {
|
---|
| 2427 | var test = new Func<ConversionB>(() => {
|
---|
| 2428 | return new ConversionB(1, 2);
|
---|
| 2429 | });
|
---|
| 2430 |
|
---|
| 2431 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 2432 | var old = test();
|
---|
| 2433 | serializer.Serialize(old, tempFile);
|
---|
| 2434 |
|
---|
[15857] | 2435 | DeregisterType(typeof(ConversionB));
|
---|
| 2436 | DeregisterType(typeof(ConversionBNew));
|
---|
| 2437 | DeregisterType(typeof(ConversionA));
|
---|
| 2438 | DeregisterType(typeof(ConversionANew));
|
---|
[15529] | 2439 |
|
---|
[15857] | 2440 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid, typeof(ConversionANew));
|
---|
| 2441 | SetTypeGuid(typeof(ConversionANew), GetTypeGuid(typeof(ConversionA)));
|
---|
| 2442 | RemoveTypeInfo(typeof(ConversionA));
|
---|
[15529] | 2443 |
|
---|
[15857] | 2444 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid, typeof(ConversionBNew));
|
---|
| 2445 | SetTypeGuid(typeof(ConversionBNew), GetTypeGuid(typeof(ConversionB)));
|
---|
| 2446 | RemoveTypeInfo(typeof(ConversionB));
|
---|
[15529] | 2447 |
|
---|
| 2448 | object o = serializer.Deserialize(tempFile);
|
---|
| 2449 | var restored = (ConversionBNew)o;
|
---|
| 2450 | Assert.AreEqual(restored.g, old.f);
|
---|
| 2451 | Assert.AreEqual(restored.BaseG, old.BaseF);
|
---|
| 2452 | }
|
---|
[15857] | 2453 |
|
---|
| 2454 | [StorableType("90470973-4559-428E-AF28-DD95866B0A84")]
|
---|
| 2455 | private class A0 {
|
---|
| 2456 | [Storable]
|
---|
| 2457 | public int x;
|
---|
| 2458 | }
|
---|
| 2459 |
|
---|
| 2460 | [StorableType("00000000-0000-0000-0000-0000000000A1", 2)]
|
---|
| 2461 | private class A1 {
|
---|
| 2462 | [Storable]
|
---|
| 2463 | public int y;
|
---|
| 2464 | }
|
---|
| 2465 |
|
---|
| 2466 | [StorableType("847DD840-3EE3-4A01-AC60-FD7E71ED05F8")]
|
---|
| 2467 | private class B0 {
|
---|
| 2468 | [Storable]
|
---|
| 2469 | public int x;
|
---|
| 2470 | }
|
---|
| 2471 |
|
---|
| 2472 | [StorableType("00000000-0000-0000-0000-0000000000B1", 2)]
|
---|
| 2473 | private class B1 : A0 { }
|
---|
| 2474 |
|
---|
| 2475 | [StorableType("00000000-0000-0000-0000-0000000000B2", 3)]
|
---|
| 2476 | private class B2 {
|
---|
| 2477 | [Storable]
|
---|
| 2478 | public int x;
|
---|
| 2479 | }
|
---|
| 2480 |
|
---|
| 2481 | private static class ConversionsA2A_B2B {
|
---|
| 2482 | [StorableConversion("847DD840-3EE3-4A01-AC60-FD7E71ED05F8", 1, baseGuid: "90470973-4559-428E-AF28-DD95866B0A84", baseVersion: 1)]
|
---|
| 2483 | private static Dictionary<string, object> ConvertB0_B1(Dictionary<string, object> values) {
|
---|
| 2484 | var newValues = new Dictionary<string, object>();
|
---|
| 2485 | newValues["90470973-4559-428E-AF28-DD95866B0A84.x"] = values["847DD840-3EE3-4A01-AC60-FD7E71ED05F8.x"];
|
---|
| 2486 | return newValues;
|
---|
| 2487 | }
|
---|
| 2488 |
|
---|
| 2489 | [StorableConversion("90470973-4559-428E-AF28-DD95866B0A84", 1)]
|
---|
| 2490 | private static Dictionary<string, object> ConvertA0_A1(Dictionary<string, object> values) {
|
---|
| 2491 | var newValues = new Dictionary<string, object>();
|
---|
| 2492 | newValues["90470973-4559-428E-AF28-DD95866B0A84.y"] = values["90470973-4559-428E-AF28-DD95866B0A84.x"];
|
---|
| 2493 | return newValues;
|
---|
| 2494 | }
|
---|
| 2495 |
|
---|
| 2496 | [StorableConversion("847DD840-3EE3-4A01-AC60-FD7E71ED05F8", 2)]
|
---|
| 2497 | private static Dictionary<string, object> ConvertB1_B2(Dictionary<string, object> values) {
|
---|
| 2498 | var newValues = new Dictionary<string, object>();
|
---|
| 2499 | newValues["847DD840-3EE3-4A01-AC60-FD7E71ED05F8.x"] = values["90470973-4559-428E-AF28-DD95866B0A84.y"];
|
---|
| 2500 | return newValues;
|
---|
| 2501 | }
|
---|
| 2502 | }
|
---|
| 2503 |
|
---|
| 2504 | [TestMethod]
|
---|
| 2505 | [TestCategory("PersistenceNew")]
|
---|
| 2506 | [TestProperty("Time", "short")]
|
---|
| 2507 | public void TestConversionCase2() {
|
---|
| 2508 | var test = new Func<B0>(() => {
|
---|
| 2509 | return new B0() { x = 17 };
|
---|
| 2510 | });
|
---|
| 2511 |
|
---|
| 2512 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 2513 | var old = test();
|
---|
| 2514 | serializer.Serialize(old, tempFile);
|
---|
| 2515 |
|
---|
| 2516 | DeregisterType(typeof(B0));
|
---|
| 2517 | DeregisterType(typeof(B1));
|
---|
| 2518 | DeregisterType(typeof(B2));
|
---|
| 2519 | DeregisterType(typeof(A0));
|
---|
| 2520 | DeregisterType(typeof(A1));
|
---|
| 2521 |
|
---|
| 2522 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(B0)).Guid, typeof(B2));
|
---|
| 2523 | SetTypeGuid(typeof(B2), GetTypeGuid(typeof(B0)));
|
---|
| 2524 | RemoveTypeInfo(typeof(B0));
|
---|
| 2525 |
|
---|
| 2526 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(A0)).Guid, typeof(A1));
|
---|
| 2527 | SetTypeGuid(typeof(A1), GetTypeGuid(typeof(A0)));
|
---|
| 2528 | RemoveTypeInfo(typeof(A0));
|
---|
| 2529 |
|
---|
| 2530 | object o = serializer.Deserialize(tempFile);
|
---|
| 2531 | var restored = (B2)o;
|
---|
| 2532 | Assert.AreEqual(restored.x, old.x);
|
---|
| 2533 | }
|
---|
| 2534 |
|
---|
| 2535 | #region Inheritance Chain Test
|
---|
| 2536 | [StorableType("C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95")]
|
---|
| 2537 | private class InheritanceA0 {
|
---|
| 2538 | [Storable]
|
---|
| 2539 | public int x;
|
---|
| 2540 | }
|
---|
| 2541 |
|
---|
| 2542 | [StorableType("00000000-0000-0000-0000-0000000001A1", 2)]
|
---|
| 2543 | private class InheritanceA1 {
|
---|
| 2544 | [Storable]
|
---|
| 2545 | public int y;
|
---|
| 2546 | }
|
---|
| 2547 |
|
---|
| 2548 | [StorableType("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1)]
|
---|
| 2549 | private class InheritanceC0 {
|
---|
| 2550 | [Storable]
|
---|
| 2551 | public int x;
|
---|
| 2552 | }
|
---|
| 2553 |
|
---|
| 2554 | [StorableType("00000000-0000-0000-0000-0000000001C1", 2)]
|
---|
| 2555 | private class InheritanceC1 {
|
---|
| 2556 | [Storable]
|
---|
| 2557 | public int x;
|
---|
| 2558 | }
|
---|
| 2559 |
|
---|
| 2560 | [StorableType("41108958-227D-43C4-B049-80AD0D3DB7F6")]
|
---|
| 2561 | private class InheritanceB0 : InheritanceA0 {
|
---|
| 2562 | //[Storable]
|
---|
| 2563 | //public int x;
|
---|
| 2564 | }
|
---|
| 2565 |
|
---|
| 2566 | [StorableType("00000000-0000-0000-0000-0000000001B1", 2)]
|
---|
| 2567 | private class InheritanceB1 : InheritanceC1 { }
|
---|
| 2568 |
|
---|
| 2569 | private static class InheritanceConversionsA2A_B2B {
|
---|
| 2570 | [StorableConversion("C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95", 1)]
|
---|
| 2571 | private static Dictionary<string, object> ConvertA0_A1(Dictionary<string, object> values) {
|
---|
| 2572 | var newValues = new Dictionary<string, object>();
|
---|
| 2573 | newValues["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.x"];
|
---|
| 2574 | return newValues;
|
---|
| 2575 | }
|
---|
| 2576 |
|
---|
| 2577 | [StorableConversion("41108958-227D-43C4-B049-80AD0D3DB7F6", 1, baseGuid: "C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95", baseVersion: 2)]
|
---|
| 2578 | private static Dictionary<string, object> ConvertB0_B1(Dictionary<string, object> values, out List<Tuple<string, uint>> typeChain) {
|
---|
| 2579 | typeChain = new List<Tuple<string, uint>> {
|
---|
| 2580 | Tuple.Create("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1u)
|
---|
| 2581 | };
|
---|
| 2582 |
|
---|
| 2583 | var newValues = new Dictionary<string, object>();
|
---|
| 2584 | newValues["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"];
|
---|
| 2585 | newValues["28A5F6B8-49AF-4C6A-AF0E-F92EB4511722.x"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"];
|
---|
| 2586 | return newValues;
|
---|
| 2587 | }
|
---|
| 2588 |
|
---|
| 2589 | [StorableConversion("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1)]
|
---|
| 2590 | private static Dictionary<string, object> ConvertC0_C1(Dictionary<string, object> values) {
|
---|
| 2591 | var newValues = new Dictionary<string, object>();
|
---|
| 2592 | newValues["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] = (int)values["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] * 2;
|
---|
| 2593 | return newValues;
|
---|
| 2594 | }
|
---|
| 2595 | }
|
---|
| 2596 |
|
---|
| 2597 | [TestMethod]
|
---|
| 2598 | [TestCategory("PersistenceNew")]
|
---|
| 2599 | [TestProperty("Time", "short")]
|
---|
| 2600 | public void TestInheritanceConversionCase1() {
|
---|
| 2601 | var test = new Func<InheritanceB0>(() => {
|
---|
| 2602 | return new InheritanceB0() { x = 17 };
|
---|
| 2603 | });
|
---|
| 2604 |
|
---|
| 2605 | ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
| 2606 | var old = test();
|
---|
| 2607 | serializer.Serialize(old, tempFile);
|
---|
| 2608 |
|
---|
| 2609 | DeregisterType(typeof(InheritanceB0));
|
---|
| 2610 | DeregisterType(typeof(InheritanceB1));
|
---|
| 2611 | DeregisterType(typeof(InheritanceA0));
|
---|
| 2612 | DeregisterType(typeof(InheritanceA1));
|
---|
| 2613 | DeregisterType(typeof(InheritanceC0));
|
---|
| 2614 | DeregisterType(typeof(InheritanceC1));
|
---|
| 2615 |
|
---|
| 2616 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceA0)).Guid, typeof(InheritanceA1));
|
---|
| 2617 | SetTypeGuid(typeof(InheritanceA1), GetTypeGuid(typeof(InheritanceA0)));
|
---|
| 2618 | RemoveTypeInfo(typeof(InheritanceA0));
|
---|
| 2619 |
|
---|
| 2620 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceB0)).Guid, typeof(InheritanceB1));
|
---|
| 2621 | SetTypeGuid(typeof(InheritanceB1), GetTypeGuid(typeof(InheritanceB0)));
|
---|
| 2622 | RemoveTypeInfo(typeof(InheritanceB0));
|
---|
| 2623 |
|
---|
| 2624 | RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceC0)).Guid, typeof(InheritanceC1));
|
---|
| 2625 | SetTypeGuid(typeof(InheritanceC1), GetTypeGuid(typeof(InheritanceC0)));
|
---|
| 2626 | RemoveTypeInfo(typeof(InheritanceC0));
|
---|
| 2627 |
|
---|
| 2628 | object o = serializer.Deserialize(tempFile);
|
---|
| 2629 | var restoredC1 = (InheritanceC1)o;
|
---|
| 2630 | var restoredB1 = (InheritanceB1)o;
|
---|
| 2631 | Assert.AreEqual(old.x, restoredB1.x);
|
---|
| 2632 | Assert.AreEqual(old.x * 2, restoredC1.x);
|
---|
| 2633 | }
|
---|
| 2634 | #endregion
|
---|
| 2635 | #endregion
|
---|
[6846] | 2636 | }
|
---|
| 2637 | }
|
---|