Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/03/17 18:21:40 (7 years ago)
Author:
jkarder
Message:

#2520: worked on persistence

Location:
branches/PersistenceOverhaul
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceOverhaul

    • Property svn:ignore
      •  

        old new  
        2424protoc.exe
        2525obj
         26.vs
  • branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs

    r13410 r14537  
    273273  }
    274274
     275  [StorableClass("FD953B0A-BDE6-41E6-91A8-CA3D90C91CDB")]
    275276  public class SimpleClass {
     277    [Storable]
    276278    public double x { get; set; }
     279    [Storable]
    277280    public int y { get; set; }
    278281  }
     
    653656    [TestCategory("Persistence4")]
    654657    [TestProperty("Time", "short")]
     658    public void TestSBytes() {
     659      var test = new Func<sbyte[]>(() => { return new sbyte[] { 3, 1 }; });
     660      ProtoBufSerializer serializer = new ProtoBufSerializer();
     661      serializer.Serialize(test(), tempFile);
     662      object o = serializer.Deserialize(tempFile);
     663      sbyte[] result = (sbyte[])o;
     664      Assert.AreEqual(test()[0], result[0]);
     665      Assert.AreEqual(test()[1], result[1]);
     666
     667      string msg = Profile(test);
     668      Console.WriteLine(msg);
     669    }
     670
     671    [TestMethod]
     672    [TestCategory("Persistence4")]
     673    [TestProperty("Time", "short")]
     674    public void TestChars() {
     675      var test = new Func<char[]>(() => { return new char[] { 'a', 'b' }; });
     676      ProtoBufSerializer serializer = new ProtoBufSerializer();
     677      serializer.Serialize(test(), tempFile);
     678      object o = serializer.Deserialize(tempFile);
     679      char[] result = (char[])o;
     680      Assert.AreEqual(test()[0], result[0]);
     681      Assert.AreEqual(test()[1], result[1]);
     682
     683      string msg = Profile(test);
     684      Console.WriteLine(msg);
     685    }
     686
     687    [TestMethod]
     688    [TestCategory("Persistence4")]
     689    [TestProperty("Time", "short")]
     690    public void TestShorts() {
     691      var test = new Func<short[]>(() => { return new short[] { 3, 1 }; });
     692      ProtoBufSerializer serializer = new ProtoBufSerializer();
     693      serializer.Serialize(test(), tempFile);
     694      object o = serializer.Deserialize(tempFile);
     695      short[] result = (short[])o;
     696      Assert.AreEqual(test()[0], result[0]);
     697      Assert.AreEqual(test()[1], result[1]);
     698
     699      string msg = Profile(test);
     700      Console.WriteLine(msg);
     701    }
     702
     703    [TestMethod]
     704    [TestCategory("Persistence4")]
     705    [TestProperty("Time", "short")]
     706    public void TestUShorts() {
     707      var test = new Func<ushort[]>(() => { return new ushort[] { 3, 1 }; });
     708      ProtoBufSerializer serializer = new ProtoBufSerializer();
     709      serializer.Serialize(test(), tempFile);
     710      object o = serializer.Deserialize(tempFile);
     711      ushort[] result = (ushort[])o;
     712      Assert.AreEqual(test()[0], result[0]);
     713      Assert.AreEqual(test()[1], result[1]);
     714
     715      string msg = Profile(test);
     716      Console.WriteLine(msg);
     717    }
     718
     719    [TestMethod]
     720    [TestCategory("Persistence4")]
     721    [TestProperty("Time", "short")]
    655722    public void TestString() {
    656723      var test = new Func<object>(() => { return "Hello World!"; });
     
    669736    [TestProperty("Time", "short")]
    670737    public void TestColor() {
    671       var test = new Func<object>(() => { return Color.DeepSkyBlue; });
     738      var test = new Func<object>(() => { return Color.FromArgb(12, 34, 56, 78); });
    672739      ProtoBufSerializer serializer = new ProtoBufSerializer();
    673740      serializer.Serialize(test(), tempFile);
     
    791858    [TestCategory("Persistence4")]
    792859    [TestProperty("Time", "short")]
     860    public void TestStack() {
     861      var test = new Func<Stack>(() => {
     862        return new Stack(new int[] { 1, 2, 3 });
     863      });
     864      ProtoBufSerializer serializer = new ProtoBufSerializer();
     865      serializer.Serialize(test(), tempFile);
     866      object o = serializer.Deserialize(tempFile);
     867      Stack result = (Stack)o;
     868      var actualStack = test();
     869      Assert.AreEqual(actualStack.Pop(), result.Pop());
     870      Assert.AreEqual(actualStack.Pop(), result.Pop());
     871      Assert.AreEqual(actualStack.Pop(), result.Pop());
     872
     873      string msg = Profile(test);
     874      Console.WriteLine(msg);
     875    }
     876
     877    [TestMethod]
     878    [TestCategory("Persistence4")]
     879    [TestProperty("Time", "short")]
     880    public void TestArrayOfStack() {
     881      var test = new Func<object[]>(() => {
     882        return new object[] {
     883          new Stack(new int[] { 1, 2, 3 }),
     884          new Stack<int>(new int[] { 1, 2, 3 }),
     885      };
     886      });
     887      ProtoBufSerializer serializer = new ProtoBufSerializer();
     888      serializer.Serialize(test(), tempFile);
     889      object o = serializer.Deserialize(tempFile);
     890      var result = (object[])o;
     891      var firstStack = (Stack)result[0];
     892      var secondStack = (Stack<int>)result[1];
     893      var actual = test();
     894      var actualFirst = (Stack)actual[0];
     895      var actualSecond = (Stack<int>)actual[1];
     896
     897      Assert.AreEqual(actualFirst.Pop(), firstStack.Pop());
     898      Assert.AreEqual(actualFirst.Pop(), firstStack.Pop());
     899      Assert.AreEqual(actualFirst.Pop(), firstStack.Pop());
     900      Assert.AreEqual(actualSecond.Pop(), secondStack.Pop());
     901      Assert.AreEqual(actualSecond.Pop(), secondStack.Pop());
     902      Assert.AreEqual(actualSecond.Pop(), secondStack.Pop());
     903
     904      string msg = Profile(test);
     905      Console.WriteLine(msg);
     906    }
     907
     908
     909    [TestMethod]
     910    [TestCategory("Persistence4")]
     911    [TestProperty("Time", "short")]
    793912    public void TestIntValueArray() {
    794913      var test = new Func<IntValue[]>(() => { return new[] { new IntValue(41), new IntValue(22), new IntValue(13) }; });
     
    797916      object o = serializer.Deserialize(tempFile);
    798917      IntValue[] result = (IntValue[])o;
    799       Assert.AreEqual(test()[0], result[0]);
    800       Assert.AreEqual(test()[1], result[1]);
    801       Assert.AreEqual(test()[2], result[2]);
     918      Assert.AreEqual(test()[0].Value, result[0].Value);
     919      Assert.AreEqual(test()[1].Value, result[1].Value);
     920      Assert.AreEqual(test()[2].Value, result[2].Value);
     921
     922      string msg = Profile(test);
     923      Console.WriteLine(msg);
     924    }
     925
     926    [TestMethod]
     927    [TestCategory("Persistence4")]
     928    [TestProperty("Time", "short")]
     929    public void TestIntValueArrayArray() {
     930      var test = new Func<IntValue[][]>(() => { return new IntValue[][] { new IntValue[] { new IntValue(41), new IntValue(22), new IntValue(13) } }; });
     931      ProtoBufSerializer serializer = new ProtoBufSerializer();
     932      serializer.Serialize(test(), tempFile);
     933      object o = serializer.Deserialize(tempFile);
     934      IntValue[][] result = (IntValue[][])o;
     935      Assert.AreEqual(test()[0][0].Value, result[0][0].Value);
     936      Assert.AreEqual(test()[0][1].Value, result[0][1].Value);
     937      Assert.AreEqual(test()[0][2].Value, result[0][2].Value);
    802938
    803939      string msg = Profile(test);
     
    809945    #region Old persistence test methods
    810946    [TestMethod]
    811     [TestCategory("Persistence")]
     947    [TestCategory("Persistence4")]
    812948    [TestProperty("Time", "short")]
    813949    public void ComplexStorable() {
     
    8991035
    9001036    [TestMethod]
    901     [TestCategory("Persistence")]
     1037    [TestCategory("Persistence4")]
    9021038    [TestProperty("Time", "short")]
    9031039    public void SelfReferences() {
     
    9271063
    9281064    [TestMethod]
    929     [TestCategory("Persistence")]
     1065    [TestCategory("Persistence4")]
    9301066    [TestProperty("Time", "short")]
    9311067    public void ArrayCreation() {
     
    9571093
    9581094    [TestMethod]
    959     [TestCategory("Persistence")]
     1095    [TestCategory("Persistence4")]
    9601096    [TestProperty("Time", "short")]
    9611097    public void CustomSerializationProperty() {
     
    9741110
    9751111    [TestMethod]
    976     [TestCategory("Persistence")]
     1112    [TestCategory("Persistence4")]
    9771113    [TestProperty("Time", "short")]
    9781114    public void Primitives() {
     
    9871123
    9881124    [TestMethod]
    989     [TestCategory("Persistence")]
     1125    [TestCategory("Persistence4")]
    9901126    [TestProperty("Time", "short")]
    9911127    public void MultiDimensionalArray() {
     
    10181154
    10191155    [TestMethod]
    1020     [TestCategory("Persistence")]
     1156    [TestCategory("Persistence4")]
    10211157    [TestProperty("Time", "short")]
    10221158    public void NestedTypeTest() {
     
    10331169
    10341170    [TestMethod]
    1035     [TestCategory("Persistence")]
     1171    [TestCategory("Persistence4")]
    10361172    [TestProperty("Time", "short")]
    10371173    public void SimpleArray() {
     
    10461182
    10471183    [TestMethod]
    1048     [TestCategory("Persistence")]
     1184    [TestCategory("Persistence4")]
    10491185    [TestProperty("Time", "short")]
    10501186    public void PrimitiveRoot() {
     
    11011237
    11021238    [TestMethod]
    1103     [TestCategory("Persistence")]
     1239    [TestCategory("Persistence4")]
    11041240    [TestProperty("Time", "short")]
    11051241    public void Enums() {
     
    11171253
    11181254    [TestMethod]
    1119     [TestCategory("Persistence")]
     1255    [TestCategory("Persistence4")]
    11201256    [TestProperty("Time", "short")]
    11211257    public void TestAliasingWithOverriddenEquals() {
     
    11351271
    11361272    [TestMethod]
    1137     [TestCategory("Persistence")]
     1273    [TestCategory("Persistence4")]
    11381274    [TestProperty("Time", "short")]
    11391275    public void NonDefaultConstructorTest() {
     
    11431279        serializer.Serialize(c, tempFile);
    11441280        Assert.Fail("Exception not thrown");
    1145       }
    1146       catch (PersistenceException) {
    1147       }
    1148     }
    1149 
    1150     [TestMethod]
    1151     [TestCategory("Persistence")]
     1281      } catch (PersistenceException) {
     1282      }
     1283    }
     1284
     1285    [TestMethod]
     1286    [TestCategory("Persistence4")]
    11521287    [TestProperty("Time", "short")]
    11531288    public void TestSavingException() {
     
    11591294        serializer.Serialize(s, tempFile);
    11601295        Assert.Fail("Exception expected");
    1161       }
    1162       catch (PersistenceException) { }
     1296      } catch (PersistenceException) { }
    11631297      List<int> newList = (List<int>)serializer.Deserialize(tempFile);
    11641298      Assert.AreEqual(list[0], newList[0]);
     
    11671301
    11681302    [TestMethod]
    1169     [TestCategory("Persistence")]
     1303    [TestCategory("Persistence4")]
    11701304    [TestProperty("Time", "short")]
    11711305    public void TestTypeStringConversion() {
     
    11791313
    11801314    [TestMethod]
    1181     [TestCategory("Persistence")]
     1315    [TestCategory("Persistence4")]
    11821316    [TestProperty("Time", "short")]
    11831317    public void TestHexadecimalPublicKeyToken() {
     
    11891323
    11901324    [TestMethod]
    1191     [TestCategory("Persistence")]
     1325    [TestCategory("Persistence4")]
    11921326    [TestProperty("Time", "short")]
    11931327    public void InheritanceTest() {
     
    12191353
    12201354    [TestMethod]
    1221     [TestCategory("Persistence")]
     1355    [TestCategory("Persistence4")]
    12221356    [TestProperty("Time", "short")]
    12231357    public void InstantiateParentChainReference() {
     
    12441378
    12451379    [TestMethod]
    1246     [TestCategory("Persistence")]
     1380    [TestCategory("Persistence4")]
    12471381    [TestProperty("Time", "short")]
    12481382    public void StructTest() {
     
    12551389
    12561390    [TestMethod]
    1257     [TestCategory("Persistence")]
     1391    [TestCategory("Persistence4")]
    12581392    [TestProperty("Time", "short")]
    12591393    public void PointTest() {
     
    12661400
    12671401    [TestMethod]
    1268     [TestCategory("Persistence")]
     1402    [TestCategory("Persistence4")]
    12691403    [TestProperty("Time", "short")]
    12701404    public void NullableValueTypes() {
     
    12801414
    12811415    [TestMethod]
    1282     [TestCategory("Persistence")]
     1416    [TestCategory("Persistence4")]
    12831417    [TestProperty("Time", "short")]
    12841418    public void BitmapTest() {
     
    13141448
    13151449    [TestMethod]
    1316     [TestCategory("Persistence")]
     1450    [TestCategory("Persistence4")]
    13171451    [TestProperty("Time", "short")]
    13181452    public void HookTest() {
     
    13471481
    13481482    [TestMethod]
    1349     [TestCategory("Persistence")]
     1483    [TestCategory("Persistence4")]
    13501484    [TestProperty("Time", "short")]
    13511485    public void TestCustomConstructor() {
     
    13681502
    13691503    [TestMethod]
    1370     [TestCategory("Persistence")]
     1504    [TestCategory("Persistence4")]
    13711505    [TestProperty("Time", "short")]
    13721506    public void TestConstructorExceptionUnwrapping() {
     
    13771511        ExplodingDefaultConstructor newX = (ExplodingDefaultConstructor)serializer.Deserialize(tempFile);
    13781512        Assert.Fail("Exception expected");
    1379       }
    1380       catch (PersistenceException pe) {
     1513      } catch (PersistenceException pe) {
    13811514        Assert.AreEqual(pe.InnerException.Message, "this constructor will always fail");
    13821515      }
     
    13841517
    13851518    [TestMethod]
    1386     [TestCategory("Persistence")]
    1387     [TestProperty("Time", "short")]
    1388     public void TestRejectionJustifications() {
    1389       ProtoBufSerializer serializer = new ProtoBufSerializer();
    1390       NonSerializable ns = new NonSerializable();
    1391       try {
    1392         serializer.Serialize(ns, tempFile);
    1393         Assert.Fail("PersistenceException expected");
    1394       }
    1395       catch (PersistenceException x) {
    1396         Assert.IsTrue(x.Message.Contains(new StorableSerializer().JustifyRejection(typeof(NonSerializable))));
    1397       }
    1398     }
    1399 
    1400     [TestMethod]
    1401     [TestCategory("Persistence")]
     1519    [TestCategory("Persistence4")]
    14021520    [TestProperty("Time", "short")]
    14031521    public void TestStreaming() {
     
    14361554
    14371555    [TestMethod]
    1438     [TestCategory("Persistence")]
     1556    [TestCategory("Persistence4")]
    14391557    [TestProperty("Time", "short")]
    14401558    public void TestLinkInheritance() {
     
    14661584
    14671585    [TestMethod]
    1468     [TestCategory("Persistence")]
     1586    [TestCategory("Persistence4")]
    14691587    [TestProperty("Time", "short")]
    14701588    public void TestStorableClassDiscoveryAllFields() {
     
    14981616
    14991617    [TestMethod]
    1500     [TestCategory("Persistence")]
     1618    [TestCategory("Persistence4")]
    15011619    [TestProperty("Time", "short")]
    15021620    public void TestStorableClassDiscoveryAllProperties() {
     
    15311649
    15321650    [TestMethod]
    1533     [TestCategory("Persistence")]
     1651    [TestCategory("Persistence4")]
    15341652    [TestProperty("Time", "short")]
    15351653    public void TestStorableClassDiscoveryAllFieldsAndAllProperties() {
     
    15631681
    15641682    [TestMethod]
    1565     [TestCategory("Persistence")]
     1683    [TestCategory("Persistence4")]
    15661684    [TestProperty("Time", "short")]
    15671685    public void TestStorableClassDiscoveryMarkedOnly() {
     
    15771695
    15781696    [TestMethod]
    1579     [TestCategory("Persistence")]
     1697    [TestCategory("Persistence4")]
    15801698    [TestProperty("Time", "short")]
    15811699    public void TestLineEndings() {
     
    15941712
    15951713    [TestMethod]
    1596     [TestCategory("Persistence")]
     1714    [TestCategory("Persistence4")]
    15971715    [TestProperty("Time", "short")]
    15981716    public void TestSpecialNumbers() {
     
    16101728
    16111729    [TestMethod]
    1612     [TestCategory("Persistence")]
     1730    [TestCategory("Persistence4")]
    16131731    [TestProperty("Time", "short")]
    16141732    public void TestStringSplit() {
     
    16331751
    16341752    [TestMethod]
    1635     [TestCategory("Persistence")]
     1753    [TestCategory("Persistence4")]
    16361754    [TestProperty("Time", "short")]
    16371755    public void TestHashSetSerializer() {
     
    16541772
    16551773    [TestMethod]
    1656     [TestCategory("Persistence")]
     1774    [TestCategory("Persistence4")]
    16571775    [TestProperty("Time", "short")]
    16581776    public void TestConcreteDictionarySerializer() {
     
    16951813
    16961814    [TestMethod]
    1697     [TestCategory("Persistence")]
     1815    [TestCategory("Persistence4")]
    16981816    [TestProperty("Time", "short")]
    16991817    public void TestReadOnlyFail() {
     
    17021820        serializer.Serialize(new ReadOnlyFail(), tempFile);
    17031821        Assert.Fail("Exception expected");
    1704       }
    1705       catch (PersistenceException) {
    1706       }
    1707       catch {
     1822      } catch (PersistenceException) {
     1823      } catch {
    17081824        Assert.Fail("PersistenceException expected");
    17091825      }
     
    17201836
    17211837    [TestMethod]
    1722     [TestCategory("Persistence")]
     1838    [TestCategory("Persistence4")]
    17231839    [TestProperty("Time", "short")]
    17241840    public void TestWriteOnlyFail() {
     
    17271843        serializer.Serialize(new WriteOnlyFail(), tempFile);
    17281844        Assert.Fail("Exception expected");
    1729       }
    1730       catch (PersistenceException) {
    1731       }
    1732       catch {
     1845      } catch (PersistenceException) {
     1846      } catch {
    17331847        Assert.Fail("PersistenceException expected.");
    17341848      }
     
    17511865    //TODO
    17521866    /* [TestMethod]
    1753      [TestCategory("Persistence")]
     1867     [TestCategory("Persistence4")]
    17541868     [TestProperty("Time", "short")]
    17551869     public void TestTypeCacheExport() {
     
    17691883
    17701884    [TestMethod]
    1771     [TestCategory("Persistence")]
     1885    [TestCategory("Persistence4")]
    17721886    [TestProperty("Time", "short")]
    17731887    public void TupleTest() {
     
    17771891      var t4 = Tuple.Create(Tuple.Create(1, 2, 3), Tuple.Create(4, 5, 6), Tuple.Create(8, 9, 10));
    17781892      var tuple = Tuple.Create(t1, t2, t3, t4);
    1779       XmlGenerator.Serialize(tuple, tempFile);
    1780       var newTuple = XmlParser.Deserialize<Tuple<Tuple<int>, Tuple<char, string>, Tuple<double, float, int>, Tuple<Tuple<int, int, int>, Tuple<int, int, int>, Tuple<int, int, int>>>>(tempFile);
     1893      SerializeNew(tuple);
     1894      var newTuple = DeserializeNew();
    17811895      Assert.AreEqual(tuple, newTuple);
    17821896    }
    17831897
    17841898    [TestMethod]
    1785     [TestCategory("Persistence")]
     1899    [TestCategory("Persistence4")]
    17861900    [TestProperty("Time", "short")]
    17871901    public void FontTest() {
     
    18021916
    18031917    [TestMethod]
    1804     [TestCategory("Persistence")]
     1918    [TestCategory("Persistence4")]
    18051919    [TestProperty("Time", "medium")]
    18061920    public void ConcurrencyTest() {
     
    18211935
    18221936    [TestMethod]
    1823     [TestCategory("Persistence")]
     1937    [TestCategory("Persistence4")]
    18241938    [TestProperty("Time", "medium")]
    18251939    public void ConcurrentBitmapTest() {
     
    18521966
    18531967    [TestMethod]
    1854     [TestCategory("Persistence")]
     1968    [TestCategory("Persistence4")]
    18551969    [TestProperty("Time", "short")]
    18561970    public void TestSpecialCharacters() {
     
    18631977
    18641978    [TestMethod]
    1865     [TestCategory("Persistence")]
     1979    [TestCategory("Persistence4")]
    18661980    [TestProperty("Time", "short")]
    18671981    public void TestByteArray() {
     
    18771991
    18781992    [TestMethod]
    1879     [TestCategory("Persistence")]
     1993    [TestCategory("Persistence4")]
    18801994    [TestProperty("Time", "short")]
    18811995    public void TestOptionalNumberEnumerable() {
     
    18882002
    18892003    [TestMethod]
    1890     [TestCategory("Persistence")]
     2004    [TestCategory("Persistence4")]
    18912005    [TestProperty("Time", "short")]
    18922006    public void TestOptionalDateTimeEnumerable() {
     
    19002014
    19012015    [TestMethod]
    1902     [TestCategory("Persistence")]
     2016    [TestCategory("Persistence4")]
    19032017    [TestProperty("Time", "short")]
    19042018    public void TestStringEnumerable() {
     
    19112025
    19122026    [TestMethod]
    1913     [TestCategory("Persistence")]
     2027    [TestCategory("Persistence4")]
    19142028    [TestProperty("Time", "short")]
    19152029    public void TestUnicodeCharArray() {
     
    19222036
    19232037    [TestMethod]
    1924     [TestCategory("Persistence")]
     2038    [TestCategory("Persistence4")]
    19252039    [TestProperty("Time", "short")]
    19262040    public void TestUnicode() {
     
    19332047
    19342048    [TestMethod]
    1935     [TestCategory("Persistence")]
     2049    [TestCategory("Persistence4")]
    19362050    [TestProperty("Time", "short")]
    19372051    public void TestQueue() {
Note: See TracChangeset for help on using the changeset viewer.