2017-09-05 22:57:45 -07:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2017-11-17 16:00:22 -08:00
|
|
|
|
using System.IO;
|
2017-09-05 22:57:45 -07:00
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Tests.Legality
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class LegalityTest
|
|
|
|
|
{
|
2017-11-17 16:00:22 -08:00
|
|
|
|
private const string LegalityWordCategory = "PKM Wordfilter Tests";
|
|
|
|
|
private const string LegalityValidCategory = "PKM Validity Tests";
|
2017-09-05 22:57:45 -07:00
|
|
|
|
|
2018-05-27 15:57:28 -07:00
|
|
|
|
static LegalityTest()
|
|
|
|
|
{
|
|
|
|
|
if (!EncounterEvent.Initialized)
|
|
|
|
|
EncounterEvent.RefreshMGDB();
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-05 22:57:45 -07:00
|
|
|
|
[TestMethod]
|
2017-11-17 16:00:22 -08:00
|
|
|
|
[TestCategory(LegalityWordCategory)]
|
2017-09-05 22:57:45 -07:00
|
|
|
|
public void BadwordTest()
|
|
|
|
|
{
|
|
|
|
|
string[] phrases =
|
|
|
|
|
{
|
|
|
|
|
"censor", "buttnugget", "18넘"
|
|
|
|
|
};
|
|
|
|
|
foreach (var phrase in phrases)
|
|
|
|
|
Assert.IsTrue(WordFilter.IsFiltered(phrase, out _), $"Word not filtered: {phrase}.");
|
|
|
|
|
}
|
2017-11-17 16:00:22 -08:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
[TestCategory(LegalityValidCategory)]
|
|
|
|
|
public void VerifyLegalityTest()
|
|
|
|
|
{
|
|
|
|
|
var folder = Directory.GetCurrentDirectory();
|
|
|
|
|
while (!folder.EndsWith(nameof(Tests)))
|
|
|
|
|
folder = Directory.GetParent(folder).FullName;
|
|
|
|
|
|
|
|
|
|
folder = Path.Combine(folder, "Legality");
|
2018-10-05 19:58:30 -07:00
|
|
|
|
ParseSettings.AllowGBCartEra = true;
|
2017-11-17 16:00:22 -08:00
|
|
|
|
VerifyAll(folder, "Legal", true);
|
2017-11-17 20:02:01 -08:00
|
|
|
|
VerifyAll(folder, "Illegal", false);
|
2017-11-17 16:00:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once UnusedParameter.Local
|
|
|
|
|
private static void VerifyAll(string folder, string name, bool IsValid)
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(folder, name);
|
|
|
|
|
Assert.IsTrue(Directory.Exists(path), $"Folder does not exist: {folder}.");
|
|
|
|
|
var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
|
|
|
|
|
foreach (var file in files)
|
|
|
|
|
{
|
|
|
|
|
var fi = new FileInfo(file);
|
|
|
|
|
Assert.IsNotNull(fi, $"Invalid file: {file}");
|
|
|
|
|
Assert.IsTrue(PKX.IsPKM(fi.Length), $"Invalid file in {fi.Directory.Name} folder.");
|
|
|
|
|
|
|
|
|
|
var data = File.ReadAllBytes(file);
|
2018-04-21 14:38:18 -07:00
|
|
|
|
var format = PKX.GetPKMFormatFromExtension(file[file.Length - 1], -1);
|
2017-11-17 16:00:22 -08:00
|
|
|
|
if (format > 10)
|
|
|
|
|
format = 6;
|
|
|
|
|
var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format);
|
|
|
|
|
Assert.IsNotNull(pkm, $"Failed to load PKM: {new FileInfo(file).Name}.");
|
|
|
|
|
|
2018-10-05 19:58:30 -07:00
|
|
|
|
ParseSettings.AllowGBCartEra = fi.DirectoryName.Contains("GBCartEra");
|
|
|
|
|
ParseSettings.AllowGen1Tradeback = fi.DirectoryName.Contains("1 Tradeback");
|
2017-11-17 16:00:22 -08:00
|
|
|
|
var legality = new LegalityAnalysis(pkm);
|
|
|
|
|
Assert.IsTrue(legality.Valid == IsValid, $"Failed to validate PKM as {(IsValid ? "Valid" : "Invalid")}: {fi.Directory.Name}\\{fi.Name}.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-05 22:57:45 -07:00
|
|
|
|
}
|
|
|
|
|
}
|