Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16467


Ignore:
Timestamp:
12/29/18 20:41:52 (6 years ago)
Author:
gkronber
Message:

#2520: added unit tests for converting all samples (open old format, store new format)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2520_PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence.Fossil/UseCases.cs

    r16466 r16467  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
    2425using System.IO;
     26using System.Linq;
     27using System.Reflection;
    2528using System.Threading.Tasks;
    2629using HEAL.Fossil;
    2730using HeuristicLab.Algorithms.GeneticAlgorithm;
     31using HeuristicLab.Common;
    2832using HeuristicLab.Persistence.Core;
     33using HeuristicLab.Persistence.Default.Xml;
    2934using Microsoft.VisualStudio.TestTools.UnitTesting;
    3035
     
    124129    }
    125130
     131
     132    [TestMethod]
     133    [TestCategory("Persistence.Fossil")]
     134    [TestProperty("Time", "short")]
     135    public void TestLoadingSamples() {
     136      var path = @"C:\reps\hl-core\branches\2520_PersistenceReintegration\HeuristicLab.Optimizer\3.3\Documents";
     137      var serializer = new ProtoBufSerializer();
     138      foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) {
     139        var original = XmlParser.Deserialize(fileName);
     140        var ok = true;
     141        foreach (var t in original.GetObjectGraphObjects().Select(o => o.GetType())) {
     142          if (
     143            t.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
     144              .Any(ctor => StorableConstructorAttribute.IsStorableConstructor(ctor))) {
     145            try {
     146              if (t.IsGenericType) {
     147                var g = Mapper.StaticCache.GetGuid(t.GetGenericTypeDefinition());
     148              } else {
     149                var g = Mapper.StaticCache.GetGuid(t);
     150              }
     151            } catch (Exception e) {
     152              Console.WriteLine(t.FullName);
     153              ok = false;
     154            }
     155          }
     156        }
     157        if (ok) {
     158          serializer.Serialize(original, fileName + ".proto");
     159          var newVersion = serializer.Deserialize(fileName + ".proto");
     160          Console.WriteLine("File: " + fileName);
     161        }
     162      }
     163    }
     164
    126165    [ClassInitialize]
    127166    public static void Initialize(TestContext testContext) {
Note: See TracChangeset for help on using the changeset viewer.