2020-01-06 05:51:53 +00:00
|
|
|
|
using System;
|
|
|
|
|
using FluentAssertions;
|
2017-09-06 05:57:45 +00:00
|
|
|
|
using PKHeX.Core;
|
2018-11-06 23:25:35 +00:00
|
|
|
|
using System.IO;
|
2020-01-06 05:51:53 +00:00
|
|
|
|
using System.Linq;
|
2018-11-06 23:25:35 +00:00
|
|
|
|
using Xunit;
|
2017-09-06 05:57:45 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Tests.Legality
|
|
|
|
|
{
|
|
|
|
|
public class LegalityTest
|
|
|
|
|
{
|
2018-05-27 22:57:28 +00:00
|
|
|
|
static LegalityTest()
|
|
|
|
|
{
|
2020-09-13 21:40:10 +00:00
|
|
|
|
if (EncounterEvent.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons);
|
|
|
|
|
EncounterEvent.RefreshMGDB();
|
2018-05-27 22:57:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("censor")]
|
|
|
|
|
[InlineData("buttnugget")]
|
|
|
|
|
[InlineData("18넘")]
|
|
|
|
|
public void CensorsBadWords(string badword)
|
2018-11-20 00:14:49 +00:00
|
|
|
|
{
|
|
|
|
|
WordFilter.IsFiltered(badword, out _).Should().BeTrue("the word should have been identified as a bad word");
|
2017-09-06 05:57:45 +00:00
|
|
|
|
}
|
2017-11-18 00:00:22 +00:00
|
|
|
|
|
2021-08-06 21:33:34 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("Legal", true)]
|
|
|
|
|
[InlineData("Illegal", false)]
|
|
|
|
|
public void TestPublicFiles(string name, bool isValid)
|
2017-11-18 00:00:22 +00:00
|
|
|
|
{
|
2019-03-19 02:33:56 +00:00
|
|
|
|
var folder = TestUtil.GetRepoPath();
|
2017-11-18 00:00:22 +00:00
|
|
|
|
folder = Path.Combine(folder, "Legality");
|
2021-08-06 21:33:34 +00:00
|
|
|
|
VerifyAll(folder, name, isValid);
|
2017-11-18 00:00:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 21:33:34 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("Legal", true)]
|
|
|
|
|
[InlineData("Illegal", false)]
|
|
|
|
|
[InlineData("PassingHacks", true)] // mad hacks, stuff to be flagged in the future
|
|
|
|
|
[InlineData("FalseFlags", false)] // legal quirks, to be fixed in the future
|
|
|
|
|
public void TestPrivateFiles(string name, bool isValid)
|
2021-08-06 20:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
var folder = TestUtil.GetRepoPath();
|
2021-08-06 20:45:32 +00:00
|
|
|
|
folder = Path.Combine(folder, "Legality", "Private");
|
2021-08-06 21:33:34 +00:00
|
|
|
|
VerifyAll(folder, name, isValid, false);
|
2021-08-06 20:19:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 00:00:22 +00:00
|
|
|
|
// ReSharper disable once UnusedParameter.Local
|
2021-08-06 21:33:34 +00:00
|
|
|
|
private static void VerifyAll(string folder, string name, bool isValid, bool checkDir = true)
|
2017-11-18 00:00:22 +00:00
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(folder, name);
|
2021-08-06 21:33:34 +00:00
|
|
|
|
bool exists = Directory.Exists(path);
|
|
|
|
|
if (checkDir)
|
|
|
|
|
exists.Should().BeTrue($"the specified test directory at '{path}' should exist");
|
|
|
|
|
else if (!exists)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-11-18 00:00:22 +00:00
|
|
|
|
var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
|
2019-03-19 02:33:56 +00:00
|
|
|
|
var ctr = 0;
|
2017-11-18 00:00:22 +00:00
|
|
|
|
foreach (var file in files)
|
|
|
|
|
{
|
|
|
|
|
var fi = new FileInfo(file);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
fi.Should().NotBeNull($"the test file '{file}' should be a valid file");
|
|
|
|
|
PKX.IsPKM(fi.Length).Should().BeTrue($"the test file '{file}' should have a valid file length");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
|
|
|
|
|
var data = File.ReadAllBytes(file);
|
2020-01-17 07:22:54 +00:00
|
|
|
|
var format = PKX.GetPKMFormatFromExtension(file[^1], -1);
|
2019-02-15 08:50:23 +00:00
|
|
|
|
format.Should().BeLessOrEqualTo(PKX.Generation, "filename is expected to have a valid extension");
|
2017-11-18 00:00:22 +00:00
|
|
|
|
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var dn = fi.DirectoryName ?? string.Empty;
|
|
|
|
|
ParseSettings.AllowGBCartEra = dn.Contains("GBCartEra");
|
|
|
|
|
ParseSettings.AllowGen1Tradeback = dn.Contains("1 Tradeback");
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format);
|
|
|
|
|
pkm.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded");
|
|
|
|
|
if (pkm == null)
|
|
|
|
|
continue;
|
2017-11-18 00:00:22 +00:00
|
|
|
|
var legality = new LegalityAnalysis(pkm);
|
2020-01-06 05:51:53 +00:00
|
|
|
|
if (legality.Valid == isValid)
|
|
|
|
|
{
|
|
|
|
|
ctr++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-03-19 02:33:56 +00:00
|
|
|
|
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var fn = Path.Combine(dn, fi.Name);
|
2020-01-06 05:51:53 +00:00
|
|
|
|
if (isValid)
|
|
|
|
|
{
|
2020-08-21 23:35:49 +00:00
|
|
|
|
var info = legality.Info;
|
2022-03-13 01:06:03 +00:00
|
|
|
|
var result = legality.Results.Cast<ICheckResult>().Concat(info.Moves).Concat(info.Relearn);
|
2020-11-14 16:20:48 +00:00
|
|
|
|
// ReSharper disable once ConstantConditionalAccessQualifier
|
2020-10-04 01:59:36 +00:00
|
|
|
|
var invalid = result.Where(z => z?.Valid == false);
|
2020-01-17 07:22:54 +00:00
|
|
|
|
var msg = string.Join(Environment.NewLine, invalid.Select(z => z.Comment));
|
|
|
|
|
legality.Valid.Should().BeTrue($"because the file '{fn}' should be Valid, but found:{Environment.NewLine}{msg}");
|
2020-01-06 05:51:53 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-17 07:22:54 +00:00
|
|
|
|
legality.Valid.Should().BeFalse($"because the file '{fn}' should be invalid, but found Valid.");
|
2020-01-06 05:51:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-07 01:50:18 +00:00
|
|
|
|
ctr.Should().BeGreaterThan(0);
|
2017-11-18 00:00:22 +00:00
|
|
|
|
}
|
2017-09-06 05:57:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|