Skip to content

Commit

Permalink
Update local-only (disabled!) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Aug 10, 2024
1 parent 57672ef commit 298464e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DBCD.Tests/Providers/WagoDBCProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
46 changes: 31 additions & 15 deletions DBCD.Tests/ReadingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Net.Http;

namespace DBCD.Tests
{
Expand Down Expand Up @@ -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");

Check warning on line 114 in DBCD.Tests/ReadingTest.cs

View workflow job for this annotation

GitHub Actions / tests

Unreachable code detected

//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)

Check warning on line 151 in DBCD.Tests/ReadingTest.cs

View workflow job for this annotation

GitHub Actions / tests

The variable 'e' is declared but never used
{
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]
Expand Down
101 changes: 89 additions & 12 deletions DBCD.Tests/WritingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;

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");

Check warning on line 24 in DBCD.Tests/WritingTest.cs

View workflow job for this annotation

GitHub Actions / tests

Unreachable code detected

//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"))
Directory.Delete("tmp", true);

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<DBCDRow>();

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)

Check warning on line 83 in DBCD.Tests/WritingTest.cs

View workflow job for this annotation

GitHub Actions / tests

The variable 'e' is declared but never used
{
// This is not a reading test, I could not care less
attemptedTables--;
continue;
}
catch (AggregateException e)
{
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);
Expand All @@ -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);
}
}
}

0 comments on commit 298464e

Please sign in to comment.