diff --git a/DBCD.Tests/Providers/WagoDBCProvider.cs b/DBCD.Tests/Providers/WagoDBCProvider.cs index 2d3c656..cd7c59d 100644 --- a/DBCD.Tests/Providers/WagoDBCProvider.cs +++ b/DBCD.Tests/Providers/WagoDBCProvider.cs @@ -56,8 +56,8 @@ public Stream StreamForTableName(string tableName, string build) var cacheFile = Path.Combine("DBCCache", build, tableName + ".db2"); if (File.Exists(cacheFile)) { - var lastWrite = File.GetLastWriteTime(cacheFile); - if (DateTime.Now - lastWrite < new TimeSpan(1, 0, 0, 0)) + //var lastWrite = File.GetLastWriteTime(cacheFile); + //if (DateTime.Now - lastWrite < new TimeSpan(1, 0, 0, 0)) return new MemoryStream(File.ReadAllBytes(cacheFile)); } diff --git a/DBCD.Tests/ReadingTest.cs b/DBCD.Tests/ReadingTest.cs index df9ca2e..3cb6b97 100644 --- a/DBCD.Tests/ReadingTest.cs +++ b/DBCD.Tests/ReadingTest.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.IO; -using System.Net.Http; namespace DBCD.Tests { @@ -112,38 +111,55 @@ public void TestGithubDBDProviderWithCache() public void TestReadingAllDB2s() { return; // Only run this test manually - - var build = "9.1.0.39653"; // WDC3 - - var dbcd = new DBCD(wagoDBCProvider, githubDBDProvider); + var localDBDProvider = new FilesystemDBDProvider("D:\\Projects\\WoWDBDefs\\definitions"); + + //var build = "3.3.5.12340"; // WDBC + //var build = "6.0.1.18179"; // WDB2 + //var build = "7.0.1.20740"; // WDB3, only 1 DBD sadly + //var build = "7.0.1.20810"; // WDB4, only 2 DBDs sadly + //var build = "7.2.0.23436"; // WDB5, only Map.db2 + //var build = "7.3.5.25928"; // WDB6 + //var build = "7.3.5.25928"; // WDC1 + //var build = "8.0.1.26231"; // WDC2 + //var build = "9.1.0.39653"; // WDC3 + //var build = "10.1.0.48480"; // WDC4 + var build = "11.0.2.56044"; // WDC5 + + var localDBCProvider = new FilesystemDBCProvider(Path.Combine("DBCCache", build)); + var dbcd = new DBCD(localDBCProvider, localDBDProvider); var allDB2s = wagoDBCProvider.GetAllTableNames(); + var attemptedTables = 0; + var successfulTables = 0; + foreach (var tableName in allDB2s) { // I think this table is meant to crash the test, so we skip it if (tableName == "UnitTestSparse") continue; + if (!localDBDProvider.ContainsBuild(tableName, build)) + continue; + + attemptedTables++; + try { var storage = dbcd.Load(tableName, build); + successfulTables++; } - catch(FileNotFoundException e) + catch (FileNotFoundException e) { Console.WriteLine($"Failed to load {tableName} for build {build}, does not exist in build."); + successfulTables++; // this counts } - catch(AggregateException e) + catch (Exception e) { - if(e.InnerException is HttpRequestException) - { - Console.WriteLine($"Failed to load {tableName} for build {build}, does not exist."); - } - else - { - throw e; - } + Console.WriteLine("Failed to load " + tableName + " for build " + build + ": " + e.Message + "\n" + e.StackTrace); } } + + Assert.AreEqual(attemptedTables, successfulTables); } //[TestMethod] diff --git a/DBCD.Tests/WritingTest.cs b/DBCD.Tests/WritingTest.cs index ab96123..710cdb6 100644 --- a/DBCD.Tests/WritingTest.cs +++ b/DBCD.Tests/WritingTest.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Http; namespace DBCD.Tests @@ -11,19 +12,29 @@ namespace DBCD.Tests [TestClass] public class WritingTest { - public static GithubDBDProvider DBDProvider { get; } = new GithubDBDProvider(true); public static string InputPath { get; } = $"{Directory.GetCurrentDirectory()}\\DBCCache"; public static WagoDBCProvider wagoDBCProvider = new(); - public static DBCD InputDBCD { get; } = new DBCD(wagoDBCProvider, DBDProvider); - public static DBCD SavedDBCD { get; } = new DBCD(new FilesystemDBCProvider("tmp"), DBDProvider); - public static string Build { get; } = "9.1.0.39653"; [TestMethod] public void TestWritingAllDB2s() { return; // Only run this test manually + var localDBDProvider = new FilesystemDBDProvider("D:\\Projects\\WoWDBDefs\\definitions"); + + //var build = "3.3.5.12340"; // WDBC + //var build = "6.0.1.18179"; // WDB2 + //var build = "7.0.1.20740"; // WDB3, TODO: Find DBDs for a DB2 + //var build = "7.0.1.20810"; // WDB4, TODO: Find DBDs for a DB2 + //var build = "7.0.3.21479"; // WDB5, TODO: Find DBDs for a DB2 + //var build = "7.2.0.23436"; // WDB6 + //var build = "7.3.5.25928"; // WDC1 + //var build = "8.0.1.26231"; // WDC2 + var build = "9.2.7.45745"; // WDC3 + //var build = "10.1.0.48480"; // WDC4 + //var build = "11.0.2.56044"; // WDC5 + var allDB2s = wagoDBCProvider.GetAllTableNames(); if (Directory.Exists("tmp")) @@ -31,26 +42,48 @@ public void TestWritingAllDB2s() Directory.CreateDirectory("tmp"); + var localDBCProvider = new FilesystemDBCProvider(Path.Combine("DBCCache", build)); + var tmpDBCProvider = new FilesystemDBCProvider("tmp"); + + var InputDBCD = new DBCD(localDBCProvider, localDBDProvider); + var SavedDBCD = new DBCD(tmpDBCProvider, localDBDProvider); + + var attemptedTables = 0; + var successfulTables = 0; + var identicalTables = 0; + foreach (var tableName in allDB2s) { - if (tableName == "UnitTestSparse") + if (!localDBDProvider.ContainsBuild(tableName, build)) continue; - // TODO: possible DBD being wrong - if (tableName == "SummonProperties") + if (tableName == "UnitTestSparse") continue; var originalValues = new List(); + attemptedTables++; + try { - var originalStorage = InputDBCD.Load(tableName, Build); + var originalStorage = InputDBCD.Load(tableName, build); + + //if(tableName == "ModelFileData") + //{ + // var row = originalStorage.ConstructRow(4252801); + // row["FileDataID"] = 4252801; + // row["Flags"] = (byte)0; + // row["LodCount"] = (byte)3; + // row["ModelResourcesID"] = (uint)62664; + //} + originalValues.AddRange(originalStorage.Values); originalStorage.Save($"tmp/{tableName}.db2"); } catch (FileNotFoundException e) { // This is not a reading test, I could not care less + attemptedTables--; continue; } catch (AggregateException e) @@ -58,16 +91,25 @@ public void TestWritingAllDB2s() if (e.InnerException is HttpRequestException) { // This is not a reading test, I could not care less + attemptedTables--; continue; } else { - throw e; + Console.WriteLine("Failed to write " + tableName + " for build " + build + ": " + e.Message + "\n" + e.StackTrace); + continue; } } + catch (Exception e) + { + Console.WriteLine("Failed to write " + tableName + " for build " + build + ": " + e.Message + "\n" + e.StackTrace); + continue; + } - var savedStorage = SavedDBCD.Load(tableName, Build); - + //try + //{ + var savedStorage = SavedDBCD.Load(tableName, build); + successfulTables++; // Lazy compare var originalJson = JsonConvert.SerializeObject(originalValues, Formatting.Indented); var newJson = JsonConvert.SerializeObject(savedStorage.Values, Formatting.Indented); @@ -78,10 +120,45 @@ public void TestWritingAllDB2s() throw new InvalidDataException($"The saved storage {tableName} should not differ from the original one!"); } + + using (var originalStream = localDBCProvider.StreamForTableName(tableName, build)) + using (var originalMS = new MemoryStream()) + using (var savedStream = tmpDBCProvider.StreamForTableName(tableName, build)) + using (var savedMS = new MemoryStream()) + { + if (originalStream.Length != savedStream.Length) + { + Console.WriteLine(originalStream.Length + " vs " + savedStream.Length + " for " + tableName + " " + build); + continue; + } + + originalStream.CopyTo(originalMS); + originalStream.Position = 0; + + savedStream.CopyTo(savedMS); + savedStream.Position = 0; + + var originalBytes = originalMS.ToArray(); + var savedBytes = savedMS.ToArray(); + + if (!originalBytes.SequenceEqual(savedBytes)) + Console.WriteLine("Different bytes for " + tableName + " " + build); + else + identicalTables++; + } + //} + //catch (Exception e) + //{ + // Console.WriteLine("Failed to load rewritten " + tableName + " for build " + build + ": " + e.Message + "\n" + e.StackTrace); + //} } + Console.WriteLine(successfulTables + "/" + attemptedTables + " written succesfully"); + Console.WriteLine(identicalTables + "/" + successfulTables + " identical (" + (successfulTables - identicalTables) + " different)"); + + Assert.AreEqual(attemptedTables, successfulTables); - Directory.Delete("tmp", true); + //Directory.Delete("tmp", true); } } }