Do code formatting in hactoolnet and test projects

This commit is contained in:
Alex Barney 2022-11-11 18:21:07 -07:00
parent 0dc556d69e
commit 100598cada
59 changed files with 309 additions and 311 deletions

View File

@ -73,4 +73,4 @@ internal class MultiBenchmark
public Action Run { get; set; }
public Func<double, string> PrintResult { get; set; }
}
}
}

View File

@ -39,6 +39,7 @@ internal static class ProcessBench
src.CopyTo(dst);
logger.ReportAdd(1);
}
encryptWatch.Stop();
logger.SetTotal(0);

View File

@ -233,4 +233,4 @@ internal class ResultLogger : Result.IResultLogger, IDisposable
return LineNumber == other.LineNumber && CallingMethod == other.CallingMethod;
}
}
}
}

View File

@ -22,18 +22,18 @@ internal class ResultNameResolver : Result.IResultNameResolver
Assembly assembly = typeof(Result).Assembly;
foreach (TypeInfo type in assembly.DefinedTypes.Where(x => x.Name.Contains("Result")))
foreach (PropertyInfo property in type.DeclaredProperties
.Where(x => x.PropertyType == typeof(Result.Base) && x.GetMethod?.IsStatic == true && x.SetMethod == null))
{
object value = property.GetValue(null, null);
if (value is null) continue;
foreach (PropertyInfo property in type.DeclaredProperties
.Where(x => x.PropertyType == typeof(Result.Base) && x.GetMethod?.IsStatic == true && x.SetMethod == null))
{
object value = property.GetValue(null, null);
if (value is null) continue;
Result resultValue = ((Result.Base)value).Value;
string name = $"{type.Name}{property.Name}";
Result resultValue = ((Result.Base)value).Value;
string name = $"{type.Name}{property.Name}";
dict[resultValue] = name;
}
dict[resultValue] = name;
}
return dict;
}
}
}

View File

@ -55,4 +55,4 @@ public class TableBuilder
return sb.ToString();
}
}
}

View File

@ -8,51 +8,51 @@ namespace LibHac.Tests;
public class AesCmac
{
public static readonly TheoryData<TestData> TestVectors = new TheoryData<TestData>
{
new TestData
{
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "".ToBytes(),
Expected = "BB1D6929E95937287FA37D129B756746".ToBytes()
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "6BC1BEE22E409F96E93D7E117393172A".ToBytes(),
Expected = "070A16B46B4D4144F79BDD9DD04A287C".ToBytes(),
Length = 0x10
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "6BC1BEE22E409F96E93D7E117393172AAE2D8A571E03AC9C9EB76FAC45AF8E5130C81C46A35CE411".ToBytes(),
Expected = "DFA66747DE9AE63030CA32611497C827".ToBytes(),
Length = 0x28
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "6BC1BEE22E409F96E93D7E117393172AAE2D8A571E03AC9C9EB76FAC45AF8E5130C81C46A35CE411E5FBC1191A0A52EFF69F2445DF4F9B17AD2B417BE66C3710".ToBytes(),
Expected = "51F0BEBF7E3B9D92FC49741779363CFE".ToBytes(),
Length = 0x40
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "00000000006BC1BEE22E409F96E93D7E117393172A0000000000".ToBytes(),
Expected = "070A16B46B4D4144F79BDD9DD04A287C".ToBytes(),
Start = 5,
Length = 0x10
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "00000000006BC1BEE22E409F96E93D7E117393172A0000000000000000000000".ToBytes(),
Expected = "070A16B46B4D4144F79BDD9DD04A287C".ToBytes(),
Start = 5,
Length = 0x10
}
};
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "".ToBytes(),
Expected = "BB1D6929E95937287FA37D129B756746".ToBytes()
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "6BC1BEE22E409F96E93D7E117393172A".ToBytes(),
Expected = "070A16B46B4D4144F79BDD9DD04A287C".ToBytes(),
Length = 0x10
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "6BC1BEE22E409F96E93D7E117393172AAE2D8A571E03AC9C9EB76FAC45AF8E5130C81C46A35CE411".ToBytes(),
Expected = "DFA66747DE9AE63030CA32611497C827".ToBytes(),
Length = 0x28
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "6BC1BEE22E409F96E93D7E117393172AAE2D8A571E03AC9C9EB76FAC45AF8E5130C81C46A35CE411E5FBC1191A0A52EFF69F2445DF4F9B17AD2B417BE66C3710".ToBytes(),
Expected = "51F0BEBF7E3B9D92FC49741779363CFE".ToBytes(),
Length = 0x40
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "00000000006BC1BEE22E409F96E93D7E117393172A0000000000".ToBytes(),
Expected = "070A16B46B4D4144F79BDD9DD04A287C".ToBytes(),
Start = 5,
Length = 0x10
},
new TestData
{
Key = "2B7E151628AED2A6ABF7158809CF4F3C".ToBytes(),
Message = "00000000006BC1BEE22E409F96E93D7E117393172A0000000000000000000000".ToBytes(),
Expected = "070A16B46B4D4144F79BDD9DD04A287C".ToBytes(),
Start = 5,
Length = 0x10
}
};
[Theory]
[MemberData(nameof(TestVectors))]
@ -73,4 +73,4 @@ public class AesCmac
public int Start;
public int Length;
}
}
}

View File

@ -8,107 +8,107 @@ namespace LibHac.Tests;
public class AesXts
{
public static readonly TheoryData<TestData> TestVectors = new TheoryData<TestData>
{
// #1 32 byte key, 32 byte PTX
new TestData
{
// #1 32 byte key, 32 byte PTX
new TestData
{
Key1 = "00000000000000000000000000000000".ToBytes(),
Key2 = "00000000000000000000000000000000".ToBytes(),
PlainText = "0000000000000000000000000000000000000000000000000000000000000000".ToBytes(),
CipherText = "917CF69EBD68B2EC9B9FE9A3EADDA692CD43D2F59598ED858C02C2652FBF922E".ToBytes(),
Sector = 0
},
Key1 = "00000000000000000000000000000000".ToBytes(),
Key2 = "00000000000000000000000000000000".ToBytes(),
PlainText = "0000000000000000000000000000000000000000000000000000000000000000".ToBytes(),
CipherText = "917CF69EBD68B2EC9B9FE9A3EADDA692CD43D2F59598ED858C02C2652FBF922E".ToBytes(),
Sector = 0
},
// #2, 32 byte key, 32 byte PTX
new TestData
{
Sector = 0x3333333333,
Key1 = "11111111111111111111111111111111".ToBytes(),
Key2 = "22222222222222222222222222222222".ToBytes(),
PlainText = "4444444444444444444444444444444444444444444444444444444444444444".ToBytes(),
CipherText = "44BEC82FFB76AEFDFBC96DFE61E192CCFA2213677C8F4FD6E4F18F7EBB69382F".ToBytes()
},
// #2, 32 byte key, 32 byte PTX
new TestData
{
Sector = 0x3333333333,
Key1 = "11111111111111111111111111111111".ToBytes(),
Key2 = "22222222222222222222222222222222".ToBytes(),
PlainText = "4444444444444444444444444444444444444444444444444444444444444444".ToBytes(),
CipherText = "44BEC82FFB76AEFDFBC96DFE61E192CCFA2213677C8F4FD6E4F18F7EBB69382F".ToBytes()
},
// #5 from xts.7, 32 byte key, 32 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "4444444444444444444444444444444444444444444444444444444444444444".ToBytes(),
CipherText = "C11839D636AD8BE5A116E48C70227763DABD3C2D1383C5DD15B2572AAA992C40".ToBytes()
},
// #5 from xts.7, 32 byte key, 32 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "4444444444444444444444444444444444444444444444444444444444444444".ToBytes(),
CipherText = "C11839D636AD8BE5A116E48C70227763DABD3C2D1383C5DD15B2572AAA992C40".ToBytes()
},
// #4, 32 byte key, 512 byte PTX
new TestData
{
Sector = 0,
Key1 = "27182818284590452353602874713526".ToBytes(),
Key2 = "31415926535897932384626433832795".ToBytes(),
PlainText = ("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" +
"202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F" +
"404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F" +
"606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F" +
"808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F" +
"A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" +
"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF" +
"E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF" +
"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" +
"202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F" +
"404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F" +
"606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F" +
"808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F" +
"A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" +
"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF" +
"E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF").ToBytes(),
CipherText = ("27A7479BEFA1D476489F308CD4CFA6E2A96E4BBE3208FF25287DD3819616E89C" +
"C78CF7F5E543445F8333D8FA7F56000005279FA5D8B5E4AD40E736DDB4D35412" +
"328063FD2AAB53E5EA1E0A9F332500A5DF9487D07A5C92CC512C8866C7E860CE" +
"93FDF166A24912B422976146AE20CE846BB7DC9BA94A767AAEF20C0D61AD0265" +
"5EA92DC4C4E41A8952C651D33174BE51A10C421110E6D81588EDE82103A252D8" +
"A750E8768DEFFFED9122810AAEB99F9172AF82B604DC4B8E51BCB08235A6F434" +
"1332E4CA60482A4BA1A03B3E65008FC5DA76B70BF1690DB4EAE29C5F1BADD03C" +
"5CCF2A55D705DDCD86D449511CEB7EC30BF12B1FA35B913F9F747A8AFD1B130E" +
"94BFF94EFFD01A91735CA1726ACD0B197C4E5B03393697E126826FB6BBDE8ECC" +
"1E08298516E2C9ED03FF3C1B7860F6DE76D4CECD94C8119855EF5297CA67E9F3" +
"E7FF72B1E99785CA0A7E7720C5B36DC6D72CAC9574C8CBBC2F801E23E56FD344" +
"B07F22154BEBA0F08CE8891E643ED995C94D9A69C9F1B5F499027A78572AEEBD" +
"74D20CC39881C213EE770B1010E4BEA718846977AE119F7A023AB58CCA0AD752" +
"AFE656BB3C17256A9F6E9BF19FDD5A38FC82BBE872C5539EDB609EF4F79C203E" +
"BB140F2E583CB2AD15B4AA5B655016A8449277DBD477EF2C8D6C017DB738B18D" +
"EB4A427D1923CE3FF262735779A418F20A282DF920147BEABE421EE5319D0568").ToBytes()
},
// #4, 32 byte key, 512 byte PTX
new TestData
{
Sector = 0,
Key1 = "27182818284590452353602874713526".ToBytes(),
Key2 = "31415926535897932384626433832795".ToBytes(),
PlainText = ("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" +
"202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F" +
"404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F" +
"606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F" +
"808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F" +
"A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" +
"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF" +
"E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF" +
"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" +
"202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F" +
"404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F" +
"606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F" +
"808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F" +
"A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" +
"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF" +
"E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF").ToBytes(),
CipherText = ("27A7479BEFA1D476489F308CD4CFA6E2A96E4BBE3208FF25287DD3819616E89C" +
"C78CF7F5E543445F8333D8FA7F56000005279FA5D8B5E4AD40E736DDB4D35412" +
"328063FD2AAB53E5EA1E0A9F332500A5DF9487D07A5C92CC512C8866C7E860CE" +
"93FDF166A24912B422976146AE20CE846BB7DC9BA94A767AAEF20C0D61AD0265" +
"5EA92DC4C4E41A8952C651D33174BE51A10C421110E6D81588EDE82103A252D8" +
"A750E8768DEFFFED9122810AAEB99F9172AF82B604DC4B8E51BCB08235A6F434" +
"1332E4CA60482A4BA1A03B3E65008FC5DA76B70BF1690DB4EAE29C5F1BADD03C" +
"5CCF2A55D705DDCD86D449511CEB7EC30BF12B1FA35B913F9F747A8AFD1B130E" +
"94BFF94EFFD01A91735CA1726ACD0B197C4E5B03393697E126826FB6BBDE8ECC" +
"1E08298516E2C9ED03FF3C1B7860F6DE76D4CECD94C8119855EF5297CA67E9F3" +
"E7FF72B1E99785CA0A7E7720C5B36DC6D72CAC9574C8CBBC2F801E23E56FD344" +
"B07F22154BEBA0F08CE8891E643ED995C94D9A69C9F1B5F499027A78572AEEBD" +
"74D20CC39881C213EE770B1010E4BEA718846977AE119F7A023AB58CCA0AD752" +
"AFE656BB3C17256A9F6E9BF19FDD5A38FC82BBE872C5539EDB609EF4F79C203E" +
"BB140F2E583CB2AD15B4AA5B655016A8449277DBD477EF2C8D6C017DB738B18D" +
"EB4A427D1923CE3FF262735779A418F20A282DF920147BEABE421EE5319D0568").ToBytes()
},
// #7, 32 byte key, 17 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "000102030405060708090A0B0C0D0E0F10".ToBytes(),
CipherText = "9E61715809A74B7E0EF033CD86181404C2".ToBytes()
},
// #7, 32 byte key, 17 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "000102030405060708090A0B0C0D0E0F10".ToBytes(),
CipherText = "9E61715809A74B7E0EF033CD86181404C2".ToBytes()
},
// #15, 32 byte key, 25 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "000102030405060708090A0B0C0D0E0F101112131415161718".ToBytes(),
CipherText = "5D0B4A86EC5A91FB849D0F826A316222C274AD93FC68C2C101".ToBytes()
},
// #15, 32 byte key, 25 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "000102030405060708090A0B0C0D0E0F101112131415161718".ToBytes(),
CipherText = "5D0B4A86EC5A91FB849D0F826A316222C274AD93FC68C2C101".ToBytes()
},
// #21, 32 byte key, 31 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E".ToBytes(),
CipherText = "42673C897D4F532CF8AA65EEB4D5B6F5C274AD93FC68C2C1015D904F33FF95".ToBytes()
}
};
// #21, 32 byte key, 31 byte PTX
new TestData
{
Sector = 0x123456789A,
Key1 = "FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0".ToBytes(),
Key2 = "BFBEBDBCBBBAB9B8B7B6B5B4B3B2B1B0".ToBytes(),
PlainText = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E".ToBytes(),
CipherText = "42673C897D4F532CF8AA65EEB4D5B6F5C274AD93FC68C2C1015D904F33FF95".ToBytes()
}
};
[Theory]
[MemberData(nameof(TestVectors))]

View File

@ -84,4 +84,4 @@ public class BufferStructTests
[StructLayout(LayoutKind.Sequential, Size = 32)]
private struct Struct32Bytes { }
}
}

View File

@ -37,4 +37,4 @@ public class FixedArraySizeTests
[Fact] public static void Array256SpanSizeIsCorrect() => Assert.Equal(256, new Array256<byte>().Items.Length);
[Fact] public static void Array256ByteSizeIsCorrect() => Assert.Equal(sizeof(byte) * 256, Unsafe.SizeOf<Array256<byte>>());
[Fact] public static void Array256LongSizeIsCorrect() => Assert.Equal(sizeof(long) * 256, Unsafe.SizeOf<Array256<long>>());
}
}

View File

@ -132,4 +132,4 @@ public class AesCbcTests
{
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv));
}
}
}

View File

@ -20,4 +20,4 @@ public class AesCtrTests
{
Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCtrEncryptor(tv.Key, tv.Iv));
}
}
}

View File

@ -132,4 +132,4 @@ public class AesEcbTests
{
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key));
}
}
}

View File

@ -23,4 +23,4 @@ public sealed class AesIntrinsicsRequiredFactAttribute : FactAttribute
Skip = "AES intrinsics required";
}
}
}
}

View File

@ -124,4 +124,4 @@ public class AesXtsTests
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateXtsDecryptor(key1, key2, tv.Iv));
}
}
}

View File

@ -44,4 +44,4 @@ internal static class Common
Assert.Equal(expectedDigest, digestBuffer);
}
}
}

View File

@ -125,4 +125,4 @@ public class RsaTests
0xf0, 0x3a, 0xf3, 0xad, 0xee, 0xd5, 0xe7, 0x42, 0x7c, 0xa5, 0xfa, 0xb6, 0xaa, 0xe6, 0x1b, 0x47,
0x54, 0xe5, 0x22, 0xeb, 0x28, 0x8a, 0x3d, 0x66, 0xe4, 0x81, 0xc2, 0x17, 0x1d, 0x0d, 0x7b, 0x5f
};
}
}

View File

@ -216,4 +216,4 @@ public class HashTestVector
public int LengthBytes { get; set; }
public byte[] Message { get; set; }
public byte[] Digest { get; set; }
}
}

View File

@ -34,4 +34,4 @@ public class Sha256Tests
{
Common.HashTestCore(tv.Message.AsSpan(0, tv.LengthBytes), tv.Digest, Sha256.CreateSha256Generator());
}
}
}

View File

@ -30,4 +30,4 @@ public class TypeSizeTests
{
Assert.Equal(0x10, Unsafe.SizeOf<Crypto.AesCmac>());
}
}
}

View File

@ -4,7 +4,6 @@ using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Ns;
using Xunit;
using static LibHac.Fs.SaveData;
namespace LibHac.Tests.Fs.FileSystemClientTests;

View File

@ -47,4 +47,4 @@ public class BcatSaveData
Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "bcat_test:/file".ToU8Span()));
Assert.Equal(DirectoryEntryType.File, type);
}
}
}

View File

@ -93,4 +93,4 @@ public class Bis
Assert.Result(ResultFs.InvalidArgument, fs.MountBis("boot1".ToU8Span(), BisPartitionId.BootPartition1Root));
}
}
}

View File

@ -7,7 +7,6 @@ using LibHac.FsSrv.Impl;
using LibHac.Ncm;
using LibHac.Time;
using Xunit;
using static LibHac.Fs.SaveData;
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests;

View File

@ -77,4 +77,4 @@ public class SdCard
fs.SetSdCardAccessibility(false);
Assert.False(fs.IsSdCardAccessible());
}
}
}

View File

@ -217,4 +217,4 @@ public static class FsaExtensions
return fs.GetFileSize(out fileSize, in pathNormalized);
}
}
}

View File

@ -5,7 +5,6 @@ using LibHac.Fs.Fsa;
using LibHac.Fs.Shim;
using LibHac.Tests.Fs.FileSystemClientTests;
using Xunit;
using static LibHac.Fs.SaveData;
namespace LibHac.Tests.Fs.FsaTests;
@ -18,11 +17,11 @@ public class MultiCommitTests
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
var saveInfo = new List<(int id, string name)>
{
(1, "Save1"),
(3, "Save2"),
(2, "Save3")
};
{
(1, "Save1"),
(3, "Save2"),
(2, "Save3")
};
foreach ((int id, string name) info in saveInfo)
{

View File

@ -136,4 +136,4 @@ public abstract partial class CommittableIFileSystemTests
Assert.Equal(data1, readData);
}
}
}

View File

@ -10,4 +10,4 @@ public abstract partial class CommittableIFileSystemTests : IFileSystemTests
}
protected abstract IReopenableFileSystemCreator GetFileSystemCreator();
}
}

View File

@ -129,4 +129,4 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests
Assert.Result(ResultFs.PathNotFound, res);
}
}
}

View File

@ -29,4 +29,4 @@ public abstract partial class IFileSystemTests
Assert.Result(ResultFs.PathNotFound, resultDir2Type);
Assert.Result(ResultFs.PathNotFound, resultFileType);
}
}
}

View File

@ -99,4 +99,4 @@ public abstract partial class IFileSystemTests
Assert.Equal(DirectoryEntryType.Directory, type1);
Assert.Equal(DirectoryEntryType.Directory, type2);
}
}
}

View File

@ -116,4 +116,4 @@ public abstract partial class IFileSystemTests
Assert.Equal(DirectoryEntryType.File, type1);
Assert.Equal(DirectoryEntryType.File, type2);
}
}
}

View File

@ -92,4 +92,4 @@ public abstract partial class IFileSystemTests
Assert.Result(ResultFs.DirectoryNotEmpty, res);
}
}
}

View File

@ -27,4 +27,4 @@ public abstract partial class IFileSystemTests
Assert.Result(ResultFs.PathNotFound, resultDir2Type);
Assert.Result(ResultFs.PathNotFound, resultFileType);
}
}
}

View File

@ -78,4 +78,4 @@ public abstract partial class IFileSystemTests
Assert.Equal(DirectoryEntryType.File, dir1Type);
}
}
}

View File

@ -24,4 +24,4 @@ public abstract partial class IFileSystemTests
Assert.Result(ResultFs.PathNotFound, fs.GetEntryType(out _, "/path".ToU8Span()));
}
}
}

View File

@ -105,4 +105,4 @@ public abstract partial class IFileSystemTests
}
}
}
}
}

View File

@ -122,4 +122,4 @@ public abstract partial class IFileSystemTests
Assert.Success(file.Get.Read(out _, 90, buffer, ReadOption.None));
Assert.Equal(bufferExpected, buffer);
}
}
}

View File

@ -24,4 +24,4 @@ public abstract partial class IFileSystemTests
Assert.Success(res);
Assert.Equal(54321, fileSize);
}
}
}

View File

@ -154,4 +154,4 @@ public abstract partial class IFileSystemTests
file.Get.Read(out _, 0, readBuffer, ReadOption.None);
Assert.Equal(bufferExpected, readBuffer);
}
}
}

View File

@ -104,4 +104,4 @@ public abstract partial class IFileSystemTests
Assert.Equal(DirectoryEntryType.Directory, dir1Type);
Assert.Equal(DirectoryEntryType.Directory, dir2Type);
}
}
}

View File

@ -22,6 +22,7 @@ public abstract partial class IFileSystemTests
Assert.Equal(DirectoryEntryType.File, type);
Assert.Result(ResultFs.PathNotFound, res);
}
[Fact]
public void RenameFile_DifferentParentDirectory_EntryIsRenamed()
{
@ -113,4 +114,4 @@ public abstract partial class IFileSystemTests
Assert.Equal(data.Length, bytesRead);
Assert.Equal(data, readData);
}
}
}

View File

@ -5,4 +5,4 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase;
public abstract partial class IFileSystemTests
{
protected abstract IFileSystem CreateFileSystem();
}
}

View File

@ -36,4 +36,4 @@ public class PathUtilityTests
Assert.Equal(expectedResult, result);
}
}
}

View File

@ -261,4 +261,4 @@ public class StorageTester
Sequential = 1,
FrequentBlock = 2
}
}
}

View File

@ -13,6 +13,7 @@ namespace LibHac.Tests.FsSystem;
public class ConcatenationFileSystemTests : IFileSystemTests
{
private const int InternalFileSize = 0x10000;
protected override IFileSystem CreateFileSystem()
{
return CreateFileSystemInternal().concatFs;

View File

@ -425,7 +425,7 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests
var baseFs = new InMemoryFileSystem();
CreateDirSaveFs(out DirectorySaveDataFileSystem saveFs, baseFs, timeStampGetter,
randomGeneratorFunc, true, true, true, null).ThrowIfFailure();
randomGeneratorFunc, true, true, true, null).ThrowIfFailure();
saveFs.CommitExtraData(true).ThrowIfFailure();
saveFs.ReadExtraData(out SaveDataExtraData extraData).ThrowIfFailure();
@ -453,7 +453,7 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests
var baseFs = new InMemoryFileSystem();
CreateDirSaveFs(out DirectorySaveDataFileSystem saveFs, baseFs, timeStampGetter,
randomGeneratorFunc, true, true, true, null).ThrowIfFailure();
randomGeneratorFunc, true, true, true, null).ThrowIfFailure();
saveFs.CommitExtraData(true).ThrowIfFailure();
saveFs.ReadExtraData(out SaveDataExtraData extraData).ThrowIfFailure();
@ -481,7 +481,7 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests
var baseFs = new InMemoryFileSystem();
CreateDirSaveFs(out DirectorySaveDataFileSystem saveFs, baseFs, timeStampGetter,
randomGeneratorFunc, true, true, true, null).ThrowIfFailure();
randomGeneratorFunc, true, true, true, null).ThrowIfFailure();
saveFs.CommitExtraData(true).ThrowIfFailure();
saveFs.ReadExtraData(out SaveDataExtraData extraData).ThrowIfFailure();

View File

@ -2,7 +2,6 @@
using LibHac.FsSystem;
using LibHac.Mem;
using Xunit;
using CacheHandle = System.UInt64;
namespace LibHac.Tests.FsSystem;

View File

@ -68,7 +68,7 @@ public class IndirectStorageTests : IClassFixture<IndirectStorageBuffers>
new()
{
RngSeed = 948285,
OriginalEntrySizeRange = new SizeRange(0x10000, 1,5),
OriginalEntrySizeRange = new SizeRange(0x10000, 1, 5),
PatchEntrySizeRange = new SizeRange(1, 0x20, 0xFFF),
StorageSize = 1024 * 1024 * 10
},
@ -76,21 +76,21 @@ public class IndirectStorageTests : IClassFixture<IndirectStorageBuffers>
new()
{
RngSeed = 236956,
OriginalEntrySizeRange = new SizeRange(0x1000, 1,10),
OriginalEntrySizeRange = new SizeRange(0x1000, 1, 10),
StorageSize = 1024 * 1024 * 10
},
// Medium patch regions
new()
{
RngSeed = 352174,
OriginalEntrySizeRange = new SizeRange(0x8000, 1,10),
OriginalEntrySizeRange = new SizeRange(0x8000, 1, 10),
StorageSize = 1024 * 1024 * 10
},
// Larger patch regions
new()
{
RngSeed = 220754,
OriginalEntrySizeRange = new SizeRange(0x10000, 10,50),
OriginalEntrySizeRange = new SizeRange(0x10000, 10, 50),
StorageSize = 1024 * 1024 * 10
}
};

View File

@ -50,4 +50,4 @@ public class FullCycleRandom
return _state;
}
}
}

View File

@ -6,7 +6,6 @@ using LibHac.Kvdb;
using LibHac.Tests.Fs.FileSystemClientTests;
using LibHac.Tools.Fs;
using Xunit;
using TTest = System.Int32;
namespace LibHac.Tests.Kvdb;

View File

@ -42,4 +42,4 @@ public class LibHacTestFramework : XunitTestFramework
{
Result.SetNameResolver(new ResultNameResolver());
}
}
}

View File

@ -12,92 +12,92 @@ public class PathToolsTests
{
public static object[][] NormalizedPathTestItems =
{
new object[] {"", "/"},
new object[] {"/", "/"},
new object[] {"/.", "/"},
new object[] {"/a/b/c", "/a/b/c"},
new object[] {"/a/b/../c", "/a/c"},
new object[] {"/a/b/c/..", "/a/b"},
new object[] {"/a/b/c/.", "/a/b/c"},
new object[] {"/a/../../..", "/"},
new object[] {"/a/../../../a/b/c", "/a/b/c"},
new object[] {"//a/b//.//c", "/a/b/c"},
new object[] {"/../a/b/c/.", "/a/b/c"},
new object[] {"/./aaa/bbb/ccc/.", "/aaa/bbb/ccc"},
new object[] { "", "/" },
new object[] { "/", "/" },
new object[] { "/.", "/" },
new object[] { "/a/b/c", "/a/b/c" },
new object[] { "/a/b/../c", "/a/c" },
new object[] { "/a/b/c/..", "/a/b" },
new object[] { "/a/b/c/.", "/a/b/c" },
new object[] { "/a/../../..", "/" },
new object[] { "/a/../../../a/b/c", "/a/b/c" },
new object[] { "//a/b//.//c", "/a/b/c" },
new object[] { "/../a/b/c/.", "/a/b/c" },
new object[] { "/./aaa/bbb/ccc/.", "/aaa/bbb/ccc" },
new object[] {"/a/b/c/", "/a/b/c/"},
new object[] {"a/b/c/", "/a/b/c/"},
new object[] {"/aa/./bb/../cc/", "/aa/cc/"},
new object[] {"/./b/../c/", "/c/"},
new object[] {"/a/../../../", "/"},
new object[] {"//a/b//.//c/", "/a/b/c/"},
new object[] {"/tmp/../", "/"},
new object[] { "/a/b/c/", "/a/b/c/" },
new object[] { "a/b/c/", "/a/b/c/" },
new object[] { "/aa/./bb/../cc/", "/aa/cc/" },
new object[] { "/./b/../c/", "/c/" },
new object[] { "/a/../../../", "/" },
new object[] { "//a/b//.//c/", "/a/b/c/" },
new object[] { "/tmp/../", "/" },
new object[] {"a", "/a"},
new object[] {"a/../../../a/b/c", "/a/b/c"},
new object[] {"./b/../c/", "/c/"},
new object[] {".", "/"},
new object[] {"..", "/"},
new object[] {"../a/b/c/.", "/a/b/c"},
new object[] {"./a/b/c/.", "/a/b/c"},
new object[] { "a", "/a" },
new object[] { "a/../../../a/b/c", "/a/b/c" },
new object[] { "./b/../c/", "/c/" },
new object[] { ".", "/" },
new object[] { "..", "/" },
new object[] { "../a/b/c/.", "/a/b/c" },
new object[] { "./a/b/c/.", "/a/b/c" },
new object[] {"a:/a/b/c", "a:/a/b/c"},
new object[] {"mount:/a/b/../c", "mount:/a/c"},
new object[] {"mount:", "mount:/"},
new object[] {"abc:/a/../../../a/b/c", "abc:/a/b/c"},
new object[] {"abc:/./b/../c/", "abc:/c/"},
new object[] {"abc:/.", "abc:/"},
new object[] {"abc:/..", "abc:/"},
new object[] {"abc:/", "abc:/"},
new object[] {"abc://a/b//.//c", "abc:/a/b/c"},
new object[] {"abc:/././/././a/b//.//c", "abc:/a/b/c"},
new object[] {"mount:/d./aa", "mount:/d./aa"},
};
new object[] { "a:/a/b/c", "a:/a/b/c" },
new object[] { "mount:/a/b/../c", "mount:/a/c" },
new object[] { "mount:", "mount:/" },
new object[] { "abc:/a/../../../a/b/c", "abc:/a/b/c" },
new object[] { "abc:/./b/../c/", "abc:/c/" },
new object[] { "abc:/.", "abc:/" },
new object[] { "abc:/..", "abc:/" },
new object[] { "abc:/", "abc:/" },
new object[] { "abc://a/b//.//c", "abc:/a/b/c" },
new object[] { "abc:/././/././a/b//.//c", "abc:/a/b/c" },
new object[] { "mount:/d./aa", "mount:/d./aa" },
};
public static object[][] SubPathTestItems =
{
new object[] {"/", "/", false},
new object[] {"/", "/a", true},
new object[] {"/", "/a/", true},
new object[] { "/", "/", false },
new object[] { "/", "/a", true },
new object[] { "/", "/a/", true },
new object[] {"/a/b/c", "/a/b/c/d", true},
new object[] {"/a/b/c/", "/a/b/c/d", true},
new object[] { "/a/b/c", "/a/b/c/d", true },
new object[] { "/a/b/c/", "/a/b/c/d", true },
new object[] {"/a/b/c", "/a/b/c", false},
new object[] {"/a/b/c/", "/a/b/c/", false},
new object[] {"/a/b/c/", "/a/b/c", false},
new object[] {"/a/b/c", "/a/b/c/", false},
new object[] { "/a/b/c", "/a/b/c", false },
new object[] { "/a/b/c/", "/a/b/c/", false },
new object[] { "/a/b/c/", "/a/b/c", false },
new object[] { "/a/b/c", "/a/b/c/", false },
new object[] {"/a/b/c/", "/a/b/cdef", false},
new object[] {"/a/b/c", "/a/b/cdef", false},
new object[] {"/a/b/c/", "/a/b/cd", false},
new object[] { "/a/b/c/", "/a/b/cdef", false },
new object[] { "/a/b/c", "/a/b/cdef", false },
new object[] { "/a/b/c/", "/a/b/cd", false },
new object[] {"mount:/", "mount:/", false},
new object[] {"mount:/", "mount:/a", true},
new object[] {"mount:/", "mount:/a/", true},
new object[] { "mount:/", "mount:/", false },
new object[] { "mount:/", "mount:/a", true },
new object[] { "mount:/", "mount:/a/", true },
new object[] {"mount:/a/b/c", "mount:/a/b/c/d", true},
new object[] {"mount:/a/b/c/", "mount:/a/b/c/d", true},
new object[] { "mount:/a/b/c", "mount:/a/b/c/d", true },
new object[] { "mount:/a/b/c/", "mount:/a/b/c/d", true },
new object[] {"mount:/a/b/c", "mount:/a/b/c", false},
new object[] {"mount:/a/b/c/", "mount:/a/b/c/", false},
new object[] {"mount:/a/b/c/", "mount:/a/b/c", false},
new object[] {"mount:/a/b/c", "mount:/a/b/c/", false},
new object[] { "mount:/a/b/c", "mount:/a/b/c", false },
new object[] { "mount:/a/b/c/", "mount:/a/b/c/", false },
new object[] { "mount:/a/b/c/", "mount:/a/b/c", false },
new object[] { "mount:/a/b/c", "mount:/a/b/c/", false },
new object[] {"mount:/a/b/c/", "mount:/a/b/cdef", false},
new object[] {"mount:/a/b/c", "mount:/a/b/cdef", false},
new object[] {"mount:/a/b/c/", "mount:/a/b/cd", false},
};
new object[] { "mount:/a/b/c/", "mount:/a/b/cdef", false },
new object[] { "mount:/a/b/c", "mount:/a/b/cdef", false },
new object[] { "mount:/a/b/c/", "mount:/a/b/cd", false },
};
public static object[][] ParentDirectoryTestItems =
{
new object[] {"/", ""},
new object[] {"/a", "/"},
new object[] {"/aa/aabc/f", "/aa/aabc"},
new object[] {"mount:/", ""},
new object[] {"mount:/a", "mount:/"},
new object[] {"mount:/aa/aabc/f", "mount:/aa/aabc"}
};
new object[] { "/", "" },
new object[] { "/a", "/" },
new object[] { "/aa/aabc/f", "/aa/aabc" },
new object[] { "mount:/", "" },
new object[] { "mount:/a", "mount:/" },
new object[] { "mount:/aa/aabc/f", "mount:/aa/aabc" }
};
public static object[][] IsNormalizedTestItems = GetNormalizedPaths(true);
@ -174,14 +174,14 @@ public class PathToolsTests
public static object[][] GetFileNameTestItems =
{
new object[] {"/a/bb/ccc", "ccc"},
new object[] {"/a/bb/ccc/", ""},
new object[] {"/a/bb", "bb"},
new object[] {"/a/bb/", ""},
new object[] {"/a", "a"},
new object[] {"/a/", ""},
new object[] {"/", ""},
};
new object[] { "/a/bb/ccc", "ccc" },
new object[] { "/a/bb/ccc/", "" },
new object[] { "/a/bb", "bb" },
new object[] { "/a/bb/", "" },
new object[] { "/a", "a" },
new object[] { "/a/", "" },
new object[] { "/", "" },
};
[Theory]
[MemberData(nameof(GetFileNameTestItems))]
@ -198,14 +198,14 @@ public class PathToolsTests
public static object[][] GetLastSegmentTestItems =
{
new object[] {"/a/bb/ccc", "ccc"},
new object[] {"/a/bb/ccc/", "ccc"},
new object[] {"/a/bb", "bb"},
new object[] {"/a/bb/", "bb"},
new object[] {"/a", "a"},
new object[] {"/a/", "a"},
new object[] {"/", ""},
};
new object[] { "/a/bb/ccc", "ccc" },
new object[] { "/a/bb/ccc/", "ccc" },
new object[] { "/a/bb", "bb" },
new object[] { "/a/bb/", "bb" },
new object[] { "/a", "a" },
new object[] { "/a/", "a" },
new object[] { "/", "" },
};
[Theory]
[MemberData(nameof(GetLastSegmentTestItems))]

View File

@ -61,4 +61,4 @@ public struct Random
buffer[i] = (byte)Next();
}
}
}
}

View File

@ -21,4 +21,4 @@ public partial class Assert
if (!expected.Includes(actual))
throw new EqualException(expected.Value, actual);
}
}
}

View File

@ -21,18 +21,18 @@ internal class ResultNameResolver : Result.IResultNameResolver
Assembly assembly = typeof(Result).Assembly;
foreach (TypeInfo type in assembly.DefinedTypes.Where(x => x.Name.Contains("Result")))
foreach (PropertyInfo property in type.DeclaredProperties
.Where(x => x.PropertyType == typeof(Result.Base) && x.GetMethod?.IsStatic == true && x.SetMethod == null))
{
object value = property.GetValue(null, null);
if (value is null) continue;
foreach (PropertyInfo property in type.DeclaredProperties
.Where(x => x.PropertyType == typeof(Result.Base) && x.GetMethod?.IsStatic == true && x.SetMethod == null))
{
object value = property.GetValue(null, null);
if (value is null) continue;
Result resultValue = ((Result.Base)value).Value;
string name = $"{type.Name}{property.Name}";
Result resultValue = ((Result.Base)value).Value;
string name = $"{type.Name}{property.Name}";
dict[resultValue] = name;
}
dict[resultValue] = name;
}
return dict;
}
}
}

View File

@ -18,4 +18,4 @@ public partial class Assert
if (!expected.SequenceEqual(actual))
throw new EqualException(expected.ToArray(), actual.ToArray());
}
}
}

View File

@ -12,4 +12,4 @@ public class TypeSizeTests
{
Assert.Equal(0x10, Unsafe.SizeOf<AccessKey>());
}
}
}

View File

@ -258,10 +258,10 @@ public class CharacterEncodingTests
public void Utf8ToUtf16_WithSmallInvalidBuffers(string utf8HexInput, CharacterEncodingResult expectedEncodingResult, string expectedUtf16Transcoding)
{
Utf8ToUtf16_String_Test_Core(
utf8Input: DecodeHex(utf8HexInput),
destinationSize: expectedUtf16Transcoding.Length,
expectedEncodingResult: expectedEncodingResult,
expectedUtf16Transcoding: expectedUtf16Transcoding);
utf8Input: DecodeHex(utf8HexInput),
destinationSize: expectedUtf16Transcoding.Length,
expectedEncodingResult: expectedEncodingResult,
expectedUtf16Transcoding: expectedUtf16Transcoding);
// Now try the tests again with a larger buffer.
// This ensures that the sequence is seen as invalid when not hitting the destination length check.
@ -660,4 +660,4 @@ public class CharacterEncodingTests
Assert.Equal(0, destination[i]);
}
}
}
}