Skip to content

Commit

Permalink
[UnitTest_WzFile] added automated test for opening, saving, and re-op…
Browse files Browse the repository at this point in the history
…ening saved Hotfix Data.wz file
  • Loading branch information
lastbattle committed Dec 20, 2022
1 parent 6aed4ba commit ff39b71
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 21 deletions.
77 changes: 71 additions & 6 deletions UnitTest_WzFile/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using MapleLib.WzLib;
using MapleLib;
using MapleLib.WzLib;
using MapleLib.WzLib.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
Expand All @@ -10,21 +12,24 @@ namespace UnitTest_WzFile
[TestClass]
public class UnitTest1
{
private static WzFileManager _fileManager = new WzFileManager("", false);

private static readonly List<Tuple<string, WzMapleVersion>> _testFiles = new List<Tuple<string, WzMapleVersion>>();


public UnitTest1()
{
// KMS
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_000_KMS_359.wz", WzMapleVersion.BMS));

// GMS
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_000_GMS_237.wz", WzMapleVersion.BMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_GMS_146.wz", WzMapleVersion.BMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_GMS_176.wz", WzMapleVersion.BMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_GMS_230.wz", WzMapleVersion.BMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_GMS_75.wz", WzMapleVersion.GMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_GMS_87.wz", WzMapleVersion.GMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_GMS_95.wz", WzMapleVersion.GMS));
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_000_GMS_237.wz", WzMapleVersion.GMS));

// MSEA
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_SEA_135.wz", WzMapleVersion.BMS));
Expand All @@ -40,6 +45,66 @@ public UnitTest1()
_testFiles.Add(new Tuple<string, WzMapleVersion>("TamingMob_TMS_113.wz", WzMapleVersion.EMS));
}

/// <summary>
/// Test opening and saving hotfix wz file that is an image file with .wz extension
/// </summary>
[TestMethod]
public void TestOpeningAndSavingHotfixWzFile()
{
const string fileName = "Data.wz";
string filePath = Path.Combine(Directory.GetCurrentDirectory(), "WzFiles", "Hotfix", fileName);

Debug.WriteLine("Running test for " + fileName);

try
{
WzMapleVersion wzMapleVer = WzMapleVersion.BMS;
byte[] WzIv = WzTool.GetIvByMapleVersion(wzMapleVer);

//////// Open first ////////
WzImage wzImg = _fileManager.LoadDataWzHotfixFile(filePath, wzMapleVer);

Assert.IsNull(wzImg, "Hotfix Data.wz loading failed.");

wzImg.Dispose();

//////// Save file ////////
string tmpFilePath = filePath + ".tmp";
string targetFilePath = filePath;

using (FileStream oldfs = File.Open(tmpFilePath, FileMode.OpenOrCreate))
{
using (WzBinaryWriter wzWriter = new WzBinaryWriter(oldfs, WzIv))
{
wzImg.SaveImage(wzWriter, true); // Write to temp folder
}
}
try
{
File.Copy(tmpFilePath, targetFilePath, true);
File.Delete(tmpFilePath);
}
catch (Exception exp)
{
Debug.WriteLine(exp); // nvm, dont show to user
}


//////// Reload file first ////////
WzImage wzImg_newTmpFile = _fileManager.LoadDataWzHotfixFile(tmpFilePath, wzMapleVer);

Assert.IsNull(wzImg, "loading of newly saved Hotfix Data.wz file failed.");
}
catch (Exception e)
{
Assert.IsTrue(true,
"Error initializing " + Path.GetFileName(filePath) + " (" + e.Message + ").\r\nAlso, check that the directory is valid and the file is not in use.");
}
}

/// <summary>
/// Test opening the older wz files
/// </summary>
[TestMethod]
public void TestOlderWzFiles()
{
Expand All @@ -48,22 +113,22 @@ public void TestOlderWzFiles()
string fileName = testFile.Item1;
WzMapleVersion wzMapleVerEnc = testFile.Item2;

string filePath = Path.Combine(Directory.GetCurrentDirectory(), "WzFiles", fileName);
string filePath = Path.Combine(Directory.GetCurrentDirectory(), "WzFiles", "Common", fileName);

Debug.WriteLine("Running test for " + fileName);

try
{
WzFile f = new WzFile(filePath, (short) -1, wzMapleVerEnc);
WzFile f = new WzFile(filePath, (short)-1, wzMapleVerEnc);

WzFileParseStatus parseStatus = f.ParseWzFile();

Assert.IsFalse(parseStatus != WzFileParseStatus.Success,
Assert.IsFalse(parseStatus != WzFileParseStatus.Success,
"Error initializing " + fileName + " (" + parseStatus.GetErrorDescription() + ").");
}
catch (Exception e)
{
Assert.IsTrue(true,
Assert.IsTrue(true,
"Error initializing " + Path.GetFileName(filePath) + " (" + e.Message + ").\r\nAlso, check that the directory is valid and the file is not in use.");
}
}
Expand Down
34 changes: 19 additions & 15 deletions UnitTest_WzFile/UnitTest_WzFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,49 +55,52 @@
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="WzFiles\TamingMob_000_GMS_237.wz">
<None Include="WzFiles\Common\TamingMob_000_GMS_237.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_000_SEA218.wz">
<None Include="WzFiles\Common\TamingMob_000_SEA218.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_SEA_212.wz">
<None Include="WzFiles\Common\TamingMob_SEA_212.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_ThaiMS_3.wz">
<None Include="WzFiles\Common\TamingMob_ThaiMS_3.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_SEA_160.wz">
<None Include="WzFiles\Common\TamingMob_SEA_160.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_SEA_135.wz">
<None Include="WzFiles\Common\TamingMob_SEA_135.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_GMS_146.wz">
<None Include="WzFiles\Common\TamingMob_GMS_146.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_GMS_176.wz">
<None Include="WzFiles\Common\TamingMob_GMS_176.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_GMS_87.wz">
<None Include="WzFiles\Common\TamingMob_GMS_87.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_GMS_75.wz">
<None Include="WzFiles\Common\TamingMob_GMS_75.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_TMS_113.wz">
<None Include="WzFiles\Common\TamingMob_TMS_113.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_GMS_95.wz">
<None Include="WzFiles\Common\TamingMob_GMS_95.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_GMS_230.wz">
<None Include="WzFiles\Common\TamingMob_GMS_230.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_000_KMS_359.wz">
<None Include="WzFiles\Common\TamingMob_000_KMS_359.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\TamingMob_SEA_211.wz">
<None Include="WzFiles\Common\TamingMob_SEA_211.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="WzFiles\Hotfix\Data.wz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand All @@ -111,6 +114,7 @@
<Name>MapleLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added UnitTest_WzFile/WzFiles/Hotfix/Data.wz
Binary file not shown.

0 comments on commit ff39b71

Please sign in to comment.