PKHeX/Tests/PKHeX.Core.Tests/Saves/HomeTests.cs
Kurt 88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00

59 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Xunit;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core.Tests.Saves;
public static class HomeTests
{
private static IEnumerable<string> GetHomeEncrypted()
{
var folder = TestUtil.GetRepoPath();
var path = Path.Combine(folder, "TestData");
return Directory.EnumerateFiles(path, "*.eh1", SearchOption.TopDirectoryOnly);
}
[Fact]
public static void CheckCrypto1()
{
var paths = GetHomeEncrypted();
foreach (var f in paths)
{
var data = File.ReadAllBytes(f);
var oldCHK = ReadUInt32LittleEndian(data.AsSpan(0xA, 4));
var chk = HomeCrypto.GetChecksum1(data);
oldCHK.Should().Be(chk);
bool encrypted = HomeCrypto.GetIsEncrypted1(data);
encrypted.Should().BeTrue();
var ph1 = new PKH(data);
ph1.DataVersion.Should().Be(1);
var decrypted = HomeCrypto.Crypt1(data);
decrypted.Length.Should().Be(data.Length);
decrypted.Length.Should().Be(ph1.Data.Length);
for (int i = 0; i < decrypted.Length; i++)
decrypted[i].Should().Be(ph1.Data[i]);
bool check = HomeCrypto.GetIsEncrypted1(decrypted);
check.Should().BeFalse();
ph1.Clone().Should().NotBeNull();
var write = ph1.Rebuild();
write.Length.Should().Be(decrypted.Length);
for (int i = 0; i < decrypted.Length; i++)
decrypted[i].Should().Be(write[i]);
var encrypt = HomeCrypto.Encrypt(write);
encrypt.Length.Should().Be(data.Length);
for (int i = 0; i < data.Length; i++)
encrypt[i].Should().Be(data[i]);
}
}
}