Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1652


Ignore:
Timestamp:
04/24/09 13:51:57 (16 years ago)
Author:
epitzer
Message:

Implement missing primitive formatter for char and add more comprehensive tests. (#548)

Location:
trunk/sources/HeuristicLab.Persistence
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs

    r1625 r1652  
    22using System.Collections;
    33using System;
     4using System.Linq;
    45using HeuristicLab.Persistence.Interfaces;
    56using HeuristicLab.Persistence.Core.Tokens;
    67using HeuristicLab.Persistence.Default.Decomposers.Storable;
     8using System.Text;
    79
    810namespace HeuristicLab.Persistence.Core {
     
    7678      throw new PersistenceException(
    7779          String.Format(
    78           "No suitable method for serializing values of type \"{0}\" found.",
    79           value.GetType().VersionInvariantName()));
     80          "No suitable method for serializing values of type \"{0}\" found\r\n" +
     81          "Formatters:\r\n{1}\r\n" +
     82          "Decomposers:\r\n{2}",
     83          value.GetType().VersionInvariantName(),
     84          string.Join("\r\n", configuration.Formatters.Select(f => f.GetType().VersionInvariantName()).ToArray()),
     85          string.Join("\r\n", configuration.Decomposers.Select(d => d.GetType().VersionInvariantName()).ToArray())
     86          ));
     87
    8088    }
    8189
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Storable/EmptyStorableClassAttribute.cs

    r1623 r1652  
    1717      if (emptyTypeInfo.ContainsKey(type))
    1818        return emptyTypeInfo[type];
     19      if (type == typeof(object)) {
     20        return true;
     21      }
    1922      foreach (var attribute in type.GetCustomAttributes(false)) {
    2023        EmptyStorableClassAttribute empty = attribute as EmptyStorableClassAttribute;
  • trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj

    r1625 r1652  
    9595    <Compile Include="Core\Configuration.cs" />
    9696    <Compile Include="Core\PersistenceException.cs" />
     97    <Compile Include="Default\DebugString\Formatters\Char2DebugStringFormatter.cs" />
    9798    <Compile Include="Default\Decomposers\Number2StringConverter.cs" />
    9899    <Compile Include="Default\Decomposers\Storable\EmptyStorableClassAttribute.cs" />
     
    137138    <Compile Include="Default\Decomposers\Storable\DataMemberAccessor.cs" />
    138139    <Compile Include="Default\Xml\Compact\IntList2XmlFormatter.cs" />
     140    <Compile Include="Default\Xml\Primitive\Char2XmlFormatter.cs" />
    139141    <Compile Include="Default\Xml\XmlStringConstants.cs" />
    140142    <Compile Include="Default\Xml\XmlString.cs" />
  • trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs

    r1644 r1652  
    1717namespace HeuristicLab.Persistence.UnitTest {
    1818
    19   public class PrimitivesTest {
     19  public class NumberTest {
    2020    [Storable]
    2121    private bool _bool = true;
     
    3636    [Storable]
    3737    private ulong _ulong = 123456;
     38  }
     39
     40  public class PrimitivesTest : NumberTest {
     41    [Storable]
     42    private char c = 'e';
    3843    [Storable]
    3944    private long[,] _long_array =
     
    4146    [Storable]
    4247    public List<int> list = new List<int> { 1, 2, 3, 4, 5 };
     48    [Storable]
     49    private object o = new object();
    4350  }
    4451
     
    132139      r.dict.Add("three", 3);
    133140      r.myEnum = TestEnum.va1;
     141      r.i = new[] { 7, 5, 6 };
     142      r.s = "new value";
     143      r.intArray = new ArrayList { 3, 2, 1 };
     144      r.intList = new List<int> { 9, 8, 7 };
     145      r.multiDimArray = new double[,] { { 5, 4, 3 }, { 1, 4, 6 } };
     146      r.boolean = false;
     147      r.dateTime = DateTime.Now;
     148      r.kvp = new KeyValuePair<string, int>("string key", 321);
     149      r.uninitialized = null;
    134150      XmlGenerator.Serialize(r, tempFile);
    135151      object o = XmlParser.DeSerialize(tempFile);
     
    140156      Assert.AreSame(newR, newR.selfReferences[0]);
    141157      Assert.AreNotSame(r, newR);
     158      Assert.AreEqual(r.myEnum, TestEnum.va1);
     159      Assert.AreEqual(r.i[0], 7);
     160      Assert.AreEqual(r.i[1], 5);
     161      Assert.AreEqual(r.i[2], 6);
     162      Assert.AreSame(r.s, "new value");
     163      Assert.AreEqual(r.intArray[0], 3);
     164      Assert.AreEqual(r.intArray[1], 2);
     165      Assert.AreEqual(r.intArray[2], 1);
     166      Assert.AreEqual(r.intList[0], 9);
     167      Assert.AreEqual(r.intList[1], 8);
     168      Assert.AreEqual(r.intList[2], 7);     
     169      Assert.AreEqual(r.multiDimArray[0, 0], 5);
     170      Assert.AreEqual(r.multiDimArray[0, 1], 4);
     171      Assert.AreEqual(r.multiDimArray[0, 2], 3);
     172      Assert.AreEqual(r.multiDimArray[1, 0], 1);
     173      Assert.AreEqual(r.multiDimArray[1, 1], 4);
     174      Assert.AreEqual(r.multiDimArray[1, 2], 6);
     175      Assert.IsFalse(r.boolean);
     176      Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10);     
     177      Assert.AreSame(r.kvp.Key, "string key");
     178      Assert.AreEqual(r.kvp.Value, 321);
     179      Assert.IsNull(r.uninitialized);
    142180    }
    143181
     
    274312    }
    275313
    276     private string formatFullMemberName(MemberInfo mi) {     
     314    private string formatFullMemberName(MemberInfo mi) {
    277315      return new StringBuilder()
    278316        .Append(mi.DeclaringType.Assembly.GetName().Name)
     
    292330      foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
    293331        if (!a.GetName().Name.StartsWith("HeuristicLab"))
    294           continue;       
     332          continue;
    295333        foreach (Type t in a.GetTypes()) {
    296334          foreach (MemberInfo mi in t.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) {
     
    304342                !mi.Name.StartsWith("set_") &&
    305343                !mi.Name.StartsWith("add_") &&
    306                 !mi.Name.StartsWith("remove_") )
     344                !mi.Name.StartsWith("remove_"))
    307345                lowerCaseMethodNames.Add(formatFullMemberName(mi));
    308346            }
     
    317355    [TestMethod]
    318356    public void Number2StringDecomposer() {
    319       PrimitivesTest sdt = new PrimitivesTest();
     357      NumberTest sdt = new NumberTest();
    320358      XmlGenerator.Serialize(sdt, tempFile,
    321359        new Configuration(new XmlFormat(),
    322           new Dictionary<Type, IFormatter> { { typeof(string), new String2XmlFormatter() } },
    323           new List<IDecomposer> { new Number2StringDecomposer() }));
    324       object o = XmlParser.DeSerialize(tempFile);     
     360          new Dictionary<Type, IFormatter> {
     361          { typeof(string), new String2XmlFormatter() } },
     362          new List<IDecomposer> {
     363            new StorableDecomposer(),
     364            new Number2StringDecomposer() }));
     365      object o = XmlParser.DeSerialize(tempFile);
    325366      Assert.AreEqual(
    326367        DebugStringGenerator.Serialize(sdt),
Note: See TracChangeset for help on using the changeset viewer.