Changeset 16462 for branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3
- Timestamp:
- 12/28/18 16:10:48 (6 years ago)
- Location:
- branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/StorableAttributeTests.cs
r16453 r16462 20 20 #endregion 21 21 22 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;22 using HEAL.Fossil; 23 23 24 24 namespace HeuristicLab.Persistence.Tests { 25 25 26 [Storable Class]26 [StorableType("EF55A82D-7D9B-486E-B811-4DCC389FDB05")] 27 27 class DemoClass { 28 28 … … 34 34 35 35 public int y = 0; 36 37 [StorableConstructor] 38 protected DemoClass(StorableConstructorFlag _) { 39 } 40 public DemoClass() { 41 } 36 42 } 37 43 38 [Storable Class]44 [StorableType("31F18F9A-C25D-449D-900A-FEBF95D7CE39")] 39 45 class Base { 40 46 public string baseName; … … 44 50 set { baseName = value; } 45 51 } 52 53 [StorableConstructor] 54 protected Base(StorableConstructorFlag _) { 55 } 56 public Base() { 57 } 46 58 } 47 59 48 [Storable Class]60 [StorableType("DF26C284-08C4-4703-A1A4-AFE834079B85")] 49 61 class Override : Base { 50 62 [Storable] … … 53 65 set { base.Name = value; } 54 66 } 67 68 [StorableConstructor] 69 protected Override(StorableConstructorFlag _) : base(_) { 70 } 71 public Override() { 72 } 55 73 } 56 74 57 [Storable Class]75 [StorableType("6BFB1984-6670-4D5E-AEAC-3E77C627AF98")] 58 76 class Intermediate : Override { 77 [StorableConstructor] 78 protected Intermediate(StorableConstructorFlag _) : base(_) { 79 } 80 public Intermediate() { 81 } 59 82 } 60 83 61 [Storable Class]84 [StorableType("856F9BDB-A20C-4B80-981B-5B4F5188FBCD")] 62 85 class New : Intermediate { 63 86 public string newName; … … 67 90 set { newName = value; } 68 91 } 92 93 [StorableConstructor] 94 protected New(StorableConstructorFlag _) : base(_) { 95 } 96 public New() { 97 } 69 98 } 70 99 } -
branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs
r16453 r16462 31 31 using System.Text.RegularExpressions; 32 32 using System.Threading.Tasks; 33 using HEAL.Fossil; 33 34 using HeuristicLab.Algorithms.GeneticAlgorithm; 34 35 using HeuristicLab.Persistence.Auxiliary; … … 43 44 using HeuristicLab.Tests; 44 45 using Microsoft.VisualStudio.TestTools.UnitTesting; 46 using Serializer = HeuristicLab.Persistence.Core.Serializer; 45 47 46 48 namespace HeuristicLab.Persistence.Tests { 47 49 48 [Storable Class]50 [StorableType("25A94A36-F3AA-4207-A3C9-54260D2A1724")] 49 51 public class NumberTest { 50 52 [Storable] … … 93 95 _ulong.GetHashCode(); 94 96 } 97 98 [StorableConstructor] 99 protected NumberTest(StorableConstructorFlag _) { 100 } 101 public NumberTest() { 102 } 95 103 } 96 104 97 [StorableClass] 98 public class NonDefaultConstructorClass { 99 [Storable] 100 int value; 101 public NonDefaultConstructorClass(int value) { 102 this.value = value; 103 } 104 } 105 106 [StorableClass] 105 [StorableType("BE44EB33-C8B7-4CDA-A564-3165558FEBE7")] 107 106 public class IntWrapper { 108 107 109 108 [Storable] 110 109 public int Value; 110 111 [StorableConstructor] 112 protected IntWrapper(StorableConstructorFlag _) { 113 } 111 114 112 115 private IntWrapper() { } … … 127 130 } 128 131 129 [Storable Class]132 [StorableType("A7865A50-E5B7-4656-8648-F375FC678BA3")] 130 133 public class PrimitivesTest : NumberTest { 131 134 [Storable] … … 155 158 o.GetHashCode(); 156 159 } 160 161 [StorableConstructor] 162 protected PrimitivesTest(StorableConstructorFlag _) : base(_) { 163 } 164 public PrimitivesTest() { 165 } 157 166 } 158 167 159 public enum TestEnum { va1, va2, va3, va8 } ; 160 161 [StorableClass] 168 [StorableType("18245FB6-D650-4378-9197-CCE6BB678F66")] 169 public enum TestEnum { va1, va2, va3, va8 }; 170 171 [StorableType("F5646F6C-DCD3-47D7-BBE5-2B33812B06D7")] 162 172 public class RootBase { 163 173 [Storable] … … 176 186 myEnum.GetHashCode(); 177 187 } 188 189 [StorableConstructor] 190 protected RootBase(StorableConstructorFlag _) { 191 } 192 public RootBase() { 193 } 178 194 } 179 195 180 [Storable Class]196 [StorableType("A9F5AFC4-20D3-4898-A7B6-E78A2CCE343B")] 181 197 public class Root : RootBase { 182 198 [Storable] … … 206 222 [Storable(DefaultValue = "default")] 207 223 public string uninitialized; 224 225 [StorableConstructor] 226 protected Root(StorableConstructorFlag _) : base(_) { 227 } 228 public Root() { 229 } 208 230 } 209 231 … … 213 235 public enum TrickyEnum { zero = 0, one = 1, two = 2 } 214 236 215 [Storable Class]237 [StorableType("969350FD-1E94-4A6F-BA95-6D2D48014E73")] 216 238 public class EnumTest { 217 239 [Storable] … … 221 243 [Storable] 222 244 public TrickyEnum trickyEnum = (TrickyEnum)15; 245 246 [StorableConstructor] 247 protected EnumTest(StorableConstructorFlag _) { 248 } 249 public EnumTest() { 250 } 223 251 } 224 252 225 [Storable Class]253 [StorableType("03CC855E-1DCA-451E-9BFB-3B06E7F96CAA")] 226 254 public class Custom { 227 255 [Storable] … … 231 259 [Storable] 232 260 public string name = "<![CDATA[<![CDATA[Serial]]>]]>"; 261 262 [StorableConstructor] 263 protected Custom(StorableConstructorFlag _) { 264 } 265 266 public Custom() { 267 268 } 233 269 } 234 270 235 [Storable Class]271 [StorableType("C3A632A5-F356-4E22-8659-BBE515638CDC")] 236 272 public class Manager { 237 273 … … 244 280 [Storable] 245 281 public double? dbl; 282 283 [StorableConstructor] 284 protected Manager(StorableConstructorFlag _) { 285 } 286 public Manager() { 287 } 246 288 } 247 289 248 [Storable Class]290 [StorableType("D694E112-47AF-47DF-8A89-F12F95FF43AB")] 249 291 public class C { 250 292 [Storable] … … 252 294 [Storable] 253 295 public KeyValuePair<List<C>, C> kvpList; 296 297 [StorableConstructor] 298 protected C(StorableConstructorFlag _) { 299 } 300 public C() { 301 } 254 302 } 255 303 … … 486 534 } 487 535 488 [Storable Class]536 [StorableType("8EA1D97E-91CD-4643-80B2-D66724E3ED4C")] 489 537 public class NestedType { 490 538 [Storable] … … 498 546 public override int GetHashCode() { 499 547 return value.GetHashCode(); 548 } 549 550 [StorableConstructor] 551 protected NestedType(StorableConstructorFlag _) { 552 } 553 public NestedType() { 500 554 } 501 555 } … … 589 643 new Configuration(new XmlFormat(), 590 644 new List<IPrimitiveSerializer> { new String2XmlSerializer() }, 591 new List<ICompositeSerializer> { 645 new List<ICompositeSerializer> { 592 646 new StorableSerializer(), 593 647 new Number2StringSerializer() })); … … 629 683 Assert.AreEqual(newInts[0], newInts[1]); 630 684 Assert.AreNotSame(newInts[0], newInts[1]); 631 }632 633 [TestMethod]634 [TestCategory("Persistence")]635 [TestProperty("Time", "short")]636 public void NonDefaultConstructorTest() {637 NonDefaultConstructorClass c = new NonDefaultConstructorClass(1);638 try {639 XmlGenerator.Serialize(c, tempFile);640 Assert.Fail("Exception not thrown");641 } catch (PersistenceException) {642 }643 685 } 644 686 … … 753 795 } 754 796 755 [Storable Class]797 [StorableType("B7140365-BA53-4E12-A095-86A3AAF5D159")] 756 798 class Child { 757 799 [Storable] 758 800 public GrandParent grandParent; 759 } 760 761 [StorableClass] 801 802 [StorableConstructor] 803 protected Child(StorableConstructorFlag _) { 804 } 805 public Child() { 806 } 807 } 808 809 [StorableType("45FAEF81-D8CD-47DB-B8DD-BBFE81F37181")] 762 810 class Parent { 763 811 [Storable] 764 812 public Child child; 765 } 766 767 [StorableClass] 813 814 [StorableConstructor] 815 protected Parent(StorableConstructorFlag _) { 816 } 817 public Parent() { 818 } 819 } 820 821 [StorableType("0668DB55-89ED-4943-B0AB-245AB3167348")] 768 822 class GrandParent { 769 823 [Storable] 770 824 public Parent parent; 825 826 [StorableConstructor] 827 protected GrandParent(StorableConstructorFlag _) { 828 } 829 public GrandParent() { 830 } 771 831 } 772 832 … … 843 903 } 844 904 845 [Storable Class]905 [StorableType("92DD18D7-A43C-4DEE-9354-81196F4DC96D")] 846 906 private class PersistenceHooks { 847 907 [Storable] … … 858 918 void PostDeserializationHook() { 859 919 sum = a + b; 920 } 921 922 [StorableConstructor] 923 protected PersistenceHooks(StorableConstructorFlag _) { 924 } 925 public PersistenceHooks() { 860 926 } 861 927 } … … 880 946 } 881 947 882 [Storable Class]948 [StorableType("3E9A9875-875F-41DD-AEEC-2924643C8E45")] 883 949 private class CustomConstructor { 884 950 public string Value = "none"; … … 887 953 } 888 954 [StorableConstructor] 889 private CustomConstructor(bool deserializing) { 890 Assert.IsTrue(deserializing); 955 private CustomConstructor(StorableConstructorFlag _) { 891 956 Value = "persistence"; 892 957 } … … 902 967 CustomConstructor newCC = (CustomConstructor)XmlParser.Deserialize(tempFile); 903 968 Assert.AreEqual(newCC.Value, "persistence"); 904 }905 906 [StorableClass]907 public class ExplodingDefaultConstructor {908 public ExplodingDefaultConstructor() {909 throw new Exception("this constructor will always fail");910 }911 public ExplodingDefaultConstructor(string password) {912 }913 }914 915 [TestMethod]916 [TestCategory("Persistence")]917 [TestProperty("Time", "short")]918 public void TestConstructorExceptionUnwrapping() {919 ExplodingDefaultConstructor x = new ExplodingDefaultConstructor("password");920 XmlGenerator.Serialize(x, tempFile);921 try {922 ExplodingDefaultConstructor newX = (ExplodingDefaultConstructor)XmlParser.Deserialize(tempFile);923 Assert.Fail("Exception expected");924 } catch (PersistenceException pe) {925 Assert.AreEqual(pe.InnerException.Message, "this constructor will always fail");926 }927 969 } 928 970 … … 954 996 } 955 997 956 [Storable Class]998 [StorableType("BC0996AA-6544-4D0F-8CBD-1FCCF08F4637")] 957 999 public class HookInheritanceTestBase { 958 1000 [Storable] … … 963 1005 link = a; 964 1006 } 965 } 966 967 [StorableClass] 1007 1008 [StorableConstructor] 1009 protected HookInheritanceTestBase(StorableConstructorFlag _) { 1010 } 1011 public HookInheritanceTestBase() { 1012 } 1013 } 1014 1015 [StorableType("E0CABA1E-EA8E-4B50-9840-1F80D23E8DC7")] 968 1016 public class HookInheritanceTestDerivedClass : HookInheritanceTestBase { 969 1017 [Storable] … … 974 1022 link = b; 975 1023 } 1024 1025 [StorableConstructor] 1026 protected HookInheritanceTestDerivedClass(StorableConstructorFlag _) : base(_) { 1027 } 1028 public HookInheritanceTestDerivedClass() { 1029 } 976 1030 } 977 1031 … … 987 1041 } 988 1042 989 [Storable Class(StorableClassType.AllFields)]1043 [StorableType(StorableMemberSelection.AllFields, "45B11367-791E-4967-86AA-D6B83EC3CDAE")] 990 1044 public class AllFieldsStorable { 991 1045 public int Value1 = 1; … … 995 1049 public int Value4 { get; private set; } 996 1050 [StorableConstructor] 997 public AllFieldsStorable(bool isDeserializing) { 998 if (!isDeserializing) { 999 Value1 = 12; 1000 Value2 = 23; 1001 Value3 = 34; 1002 Value4 = 56; 1003 } 1051 protected AllFieldsStorable(StorableConstructorFlag _) { } 1052 public AllFieldsStorable() { 1053 Value1 = 12; 1054 Value2 = 23; 1055 Value3 = 34; 1056 Value4 = 56; 1004 1057 } 1005 1058 } … … 1009 1062 [TestProperty("Time", "short")] 1010 1063 public void TestStorableClassDiscoveryAllFields() { 1011 AllFieldsStorable afs = new AllFieldsStorable( false);1064 AllFieldsStorable afs = new AllFieldsStorable(); 1012 1065 XmlGenerator.Serialize(afs, tempFile); 1013 1066 AllFieldsStorable newAfs = (AllFieldsStorable)XmlParser.Deserialize(tempFile); … … 1018 1071 } 1019 1072 1020 [Storable Class(StorableClassType.AllProperties)]1073 [StorableType(StorableMemberSelection.AllProperties, "BB7931E4-2900-430C-80FA-1CF3C41BA2C9")] 1021 1074 public class AllPropertiesStorable { 1022 1075 public int Value1 = 1; … … 1026 1079 public int Value4 { get; private set; } 1027 1080 [StorableConstructor] 1028 public AllPropertiesStorable(bool isDeserializing) { 1029 if (!isDeserializing) { 1030 Value1 = 12; 1031 Value2 = 23; 1032 Value3 = 34; 1033 Value4 = 56; 1034 } 1081 protected AllPropertiesStorable(StorableConstructorFlag _) { } 1082 public AllPropertiesStorable() { 1083 Value1 = 12; 1084 Value2 = 23; 1085 Value3 = 34; 1086 Value4 = 56; 1035 1087 } 1036 1088 } … … 1040 1092 [TestProperty("Time", "short")] 1041 1093 public void TestStorableClassDiscoveryAllProperties() { 1042 AllPropertiesStorable afs = new AllPropertiesStorable( false);1094 AllPropertiesStorable afs = new AllPropertiesStorable(); 1043 1095 XmlGenerator.Serialize(afs, tempFile); 1044 1096 AllPropertiesStorable newAfs = (AllPropertiesStorable)XmlParser.Deserialize(tempFile); … … 1050 1102 } 1051 1103 1052 [Storable Class(StorableClassType.AllFieldsAndAllProperties)]1104 [StorableType(StorableMemberSelection.AllFieldsAndAllProperties, "D81160A5-BCF9-409A-9082-EFB803C882BF")] 1053 1105 public class AllFieldsAndAllPropertiesStorable { 1054 1106 public int Value1 = 1; … … 1058 1110 public int Value4 { get; private set; } 1059 1111 [StorableConstructor] 1060 public AllFieldsAndAllPropertiesStorable(bool isDeserializing) { 1061 if (!isDeserializing) { 1062 Value1 = 12; 1063 Value2 = 23; 1064 Value3 = 34; 1065 Value4 = 56; 1066 } 1112 protected AllFieldsAndAllPropertiesStorable(StorableConstructorFlag _) { } 1113 public AllFieldsAndAllPropertiesStorable() { 1114 Value1 = 12; 1115 Value2 = 23; 1116 Value3 = 34; 1117 Value4 = 56; 1067 1118 } 1068 1119 } … … 1072 1123 [TestProperty("Time", "short")] 1073 1124 public void TestStorableClassDiscoveryAllFieldsAndAllProperties() { 1074 AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable( false);1125 AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable(); 1075 1126 XmlGenerator.Serialize(afs, tempFile); 1076 1127 AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)XmlParser.Deserialize(tempFile); … … 1081 1132 } 1082 1133 1083 [Storable Class(StorableClassType.MarkedOnly)]1134 [StorableType(StorableMemberSelection.MarkedOnly, "979BEF0C-D150-4809-9EF4-467B7CCB9665")] 1084 1135 public class MarkedOnlyStorable { 1085 1136 public int Value1 = 1; … … 1089 1140 public int Value4 { get; private set; } 1090 1141 [StorableConstructor] 1091 public MarkedOnlyStorable(bool isDeserializing) { 1092 if (!isDeserializing) { 1093 Value1 = 12; 1094 Value2 = 23; 1095 Value3 = 34; 1096 Value4 = 56; 1097 } 1142 protected MarkedOnlyStorable(StorableConstructorFlag _) { } 1143 public MarkedOnlyStorable() { 1144 Value1 = 12; 1145 Value2 = 23; 1146 Value3 = 34; 1147 Value4 = 56; 1098 1148 } 1099 1149 } … … 1103 1153 [TestProperty("Time", "short")] 1104 1154 public void TestStorableClassDiscoveryMarkedOnly() { 1105 MarkedOnlyStorable afs = new MarkedOnlyStorable( false);1155 MarkedOnlyStorable afs = new MarkedOnlyStorable(); 1106 1156 XmlGenerator.Serialize(afs, tempFile); 1107 1157 MarkedOnlyStorable newAfs = (MarkedOnlyStorable)XmlParser.Deserialize(tempFile); … … 1241 1291 } 1242 1292 1243 [Storable Class]1293 [StorableType("5F96AAB5-F68E-4A41-BA66-E56069822719")] 1244 1294 public class ReadOnlyFail { 1245 1295 [Storable] 1246 1296 public string ReadOnly { 1247 1297 get { return "fail"; } 1298 } 1299 1300 [StorableConstructor] 1301 protected ReadOnlyFail(StorableConstructorFlag _) { 1302 } 1303 public ReadOnlyFail() { 1248 1304 } 1249 1305 } … … 1263 1319 1264 1320 1265 [Storable Class]1321 [StorableType("9809F12C-B787-4BB5-9930-705673964D45")] 1266 1322 public class WriteOnlyFail { 1267 1323 [Storable] 1268 1324 public string WriteOnly { 1269 1325 set { throw new InvalidOperationException("this property should never be set."); } 1326 } 1327 1328 [StorableConstructor] 1329 protected WriteOnlyFail(StorableConstructorFlag _) { 1330 } 1331 public WriteOnlyFail() { 1270 1332 } 1271 1333 } … … 1284 1346 } 1285 1347 1286 [Storable Class]1348 [StorableType("749C5247-ABB8-4286-8208-058CC7B9C781")] 1287 1349 public class OneWayTest { 1350 [StorableConstructor] 1351 protected OneWayTest(StorableConstructorFlag _) { 1352 } 1353 1288 1354 public OneWayTest() { this.value = "default"; } 1289 1355 public string value; … … 1309 1375 Assert.AreEqual("ReadOnly", ((PrimitiveToken)it.Current).Name); it.MoveNext(); 1310 1376 Assert.AreEqual("ROOT", ((EndToken)it.Current).Name); it.MoveNext(); 1311 var deserializer = new Deserializer(new[] { 1377 var deserializer = new Deserializer(new[] { 1312 1378 new TypeMapping(0, typeof(OneWayTest).AssemblyQualifiedName, typeof(StorableSerializer).AssemblyQualifiedName), 1313 1379 new TypeMapping(1, typeof(string).AssemblyQualifiedName, typeof(String2XmlSerializer).AssemblyQualifiedName) }); … … 1461 1527 b[2] = byte.MaxValue; 1462 1528 XmlGenerator.Serialize(b, tempFile); 1463 var newB = (byte[]) 1529 var newB = (byte[])XmlParser.Deserialize(tempFile); 1464 1530 CollectionAssert.AreEqual(b, newB); 1465 1531 } … … 1469 1535 [TestProperty("Time", "short")] 1470 1536 public void TestOptionalNumberEnumerable() { 1471 var values = new List<double?> { 0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1};1537 var values = new List<double?> { 0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1 }; 1472 1538 XmlGenerator.Serialize(values, tempFile); 1473 var newValues = (List<double?>) 1539 var newValues = (List<double?>)XmlParser.Deserialize(tempFile); 1474 1540 CollectionAssert.AreEqual(values, newValues); 1475 1541 } … … 1482 1548 DateTime.ParseExact("10.09.2014 12:21", "dd.MM.yyyy hh:mm", CultureInfo.InvariantCulture), DateTime.MaxValue}; 1483 1549 XmlGenerator.Serialize(values, tempFile); 1484 var newValues = (List<DateTime?>) 1550 var newValues = (List<DateTime?>)XmlParser.Deserialize(tempFile); 1485 1551 CollectionAssert.AreEqual(values, newValues); 1486 1552 } … … 1490 1556 [TestProperty("Time", "short")] 1491 1557 public void TestStringEnumerable() { 1492 var values = new List<string> { "", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated"};1558 var values = new List<string> { "", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated" }; 1493 1559 XmlGenerator.Serialize(values, tempFile); 1494 var newValues = (List<String>) 1560 var newValues = (List<String>)XmlParser.Deserialize(tempFile); 1495 1561 CollectionAssert.AreEqual(values, newValues); 1496 1562 } … … 1500 1566 [TestProperty("Time", "short")] 1501 1567 public void TestUnicodeCharArray() { 1502 var s = Encoding.UTF8.GetChars(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb});1568 var s = Encoding.UTF8.GetChars(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb }); 1503 1569 XmlGenerator.Serialize(s, tempFile); 1504 1570 var newS = (char[])XmlParser.Deserialize(tempFile); … … 1510 1576 [TestProperty("Time", "short")] 1511 1577 public void TestUnicode() { 1512 var s = Encoding.UTF8.GetString(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb});1578 var s = Encoding.UTF8.GetString(new byte[] { 0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb }); 1513 1579 XmlGenerator.Serialize(s, tempFile); 1514 1580 var newS = XmlParser.Deserialize(tempFile); … … 1520 1586 [TestProperty("Time", "short")] 1521 1587 public void TestQueue() { 1522 var q = new Queue<int>(new[] { 1, 2, 3, 4, 0});1588 var q = new Queue<int>(new[] { 1, 2, 3, 4, 0 }); 1523 1589 XmlGenerator.Serialize(q, tempFile); 1524 1590 var newQ = (Queue<int>)XmlParser.Deserialize(tempFile);
Note: See TracChangeset
for help on using the changeset viewer.