From a4eda136dd9a0f7322755e0f81b3c98a483c1692 Mon Sep 17 00:00:00 2001
From: ThomasGoulet73 <51839772+ThomasGoulet73@users.noreply.github.com>
Date: Fri, 26 Jul 2024 07:19:04 -0400
Subject: [PATCH 1/3] Enable PresentationCore tests (#9471)
* Run PresentationCore tests
* Use previously built package native files
---
Microsoft.Dotnet.Wpf.sln | 35 +++++++++++++------
eng/Versions.props | 4 +--
.../PresentationCore/OtherAssemblyAttrs.cs | 2 +-
.../tests/Directory.Build.props | 1 -
.../tests/UnitTests/Directory.Build.targets | 27 ++++++++++++++
.../PresentationCore.Tests.csproj | 16 ++++-----
.../System.Xaml.Tests.csproj | 3 +-
7 files changed, 63 insertions(+), 25 deletions(-)
create mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/Directory.Build.targets
diff --git a/Microsoft.Dotnet.Wpf.sln b/Microsoft.Dotnet.Wpf.sln
index d9a8a779a00..aaf3a7929fa 100644
--- a/Microsoft.Dotnet.Wpf.sln
+++ b/Microsoft.Dotnet.Wpf.sln
@@ -247,12 +247,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{34B64A4A
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{A48B585E-6AB0-4F8D-8484-77F37CB44437}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFB}") = "System.Xaml.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Xaml.Tests\System.Xaml.Tests.csproj", "{B2F2A89C-55C9-41B1-A645-0948609BD8BE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Xaml.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Xaml.Tests\System.Xaml.Tests.csproj", "{B2F2A89C-55C9-41B1-A645-0948609BD8BE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluent", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Fluent\PresentationFramework.Fluent.csproj", "{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluent-ref", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Fluent\ref\PresentationFramework.Fluent-ref.csproj", "{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationCore.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\PresentationCore.Tests\PresentationCore.Tests.csproj", "{A4377D3F-6BA1-4994-945C-88667993E4F3}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1924,28 +1926,22 @@ Global
{AF9084C3-BF37-4A56-A851-89F3BAE731B3}.Release|x86.ActiveCfg = Release|Win32
{AF9084C3-BF37-4A56-A851-89F3BAE731B3}.Release|x86.Build.0 = Release|Win32
{AF9084C3-BF37-4A56-A851-89F3BAE731B3}.Release|x86.Deploy.0 = Release|Win32
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|Any CPU.ActiveCfg = Debug|Win32
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|Any CPU.Build.0 = Debug|Win32
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|Any CPU.Deploy.0 = Debug|Win32
+ {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|ARM64.ActiveCfg = Debug|ARM64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|ARM64.Build.0 = Debug|ARM64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|x64.ActiveCfg = Debug|x64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|x64.Build.0 = Debug|x64
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|x64.Deploy.0 = Debug|x64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|x86.ActiveCfg = Debug|x86
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|x86.Build.0 = Debug|x86
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Debug|x86.Deploy.0 = Debug|x86
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|Any CPU.ActiveCfg = Release|Win32
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|Any CPU.Build.0 = Release|Win32
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|Any CPU.Deploy.0 = Release|Win32
+ {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|Any CPU.Build.0 = Release|Any CPU
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|ARM64.ActiveCfg = Release|ARM64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|ARM64.Build.0 = Release|ARM64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x64.ActiveCfg = Release|x64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x64.Build.0 = Release|x64
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x64.Deploy.0 = Release|x64
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x86.ActiveCfg = Release|x86
{B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x86.Build.0 = Release|x86
- {B2F2A89C-55C9-41B1-A645-0948609BD8BE}.Release|x86.Deploy.0 = Release|x86
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}.Debug|ARM64.ActiveCfg = Debug|arm64
@@ -1978,6 +1974,22 @@ Global
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x64.Build.0 = Release|x64
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x86.ActiveCfg = Release|Any CPU
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD}.Release|x86.Build.0 = Release|Any CPU
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|ARM64.ActiveCfg = Debug|ARM64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|ARM64.Build.0 = Debug|ARM64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|x64.ActiveCfg = Debug|x64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|x64.Build.0 = Debug|x64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|x86.ActiveCfg = Debug|x86
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Debug|x86.Build.0 = Debug|x86
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|ARM64.ActiveCfg = Release|ARM64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|ARM64.Build.0 = Release|ARM64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|x64.ActiveCfg = Release|x64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|x64.Build.0 = Release|x64
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|x86.ActiveCfg = Release|x86
+ {A4377D3F-6BA1-4994-945C-88667993E4F3}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -2100,6 +2112,7 @@ Global
{B2F2A89C-55C9-41B1-A645-0948609BD8BE} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9} = {5ACFB055-649D-4A01-98C2-B0BFE7E543D6}
{3C43C553-2C1F-4EB9-8BF8-371D4A42E0FD} = {60F4058B-D35B-42D2-B276-D44B3AC579BD}
+ {A4377D3F-6BA1-4994-945C-88667993E4F3} = {A48B585E-6AB0-4F8D-8484-77F37CB44437}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4340004-DAC0-497D-B69D-CFA7CD93F567}
diff --git a/eng/Versions.props b/eng/Versions.props
index 5b79c203f59..715134fb808 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -86,10 +86,10 @@
- 2.4.0
+ 2.9.0
$(XUnitVersion)
$(XUnitVersion)
- 2.4.0
+ 2.8.1
$(XUnitVersion)
1.2.46-alpha
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/OtherAssemblyAttrs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/OtherAssemblyAttrs.cs
index 27f27befc91..b965544d04b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/OtherAssemblyAttrs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/OtherAssemblyAttrs.cs
@@ -18,7 +18,7 @@
[assembly:InternalsVisibleTo(BuildInfo.PresentationFrameworkSystemDrawing)]
[assembly:InternalsVisibleTo(BuildInfo.SystemWindowsControlsRibbon)]
[assembly:InternalsVisibleTo(BuildInfo.WindowsFormsIntegration)]
-[assembly:InternalsVisibleTo("PresentationCore.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
+[assembly:InternalsVisibleTo($"PresentationCore.Tests, PublicKey={BuildInfo.WCP_PUBLIC_KEY_STRING}")]
[assembly: TypeForwardedTo(typeof(System.Windows.Markup.IUriContext))]
[assembly: TypeForwardedTo(typeof(System.Windows.Media.TextFormattingMode))]
[assembly: TypeForwardedTo(typeof(System.Windows.Input.ICommand))]
diff --git a/src/Microsoft.DotNet.Wpf/tests/Directory.Build.props b/src/Microsoft.DotNet.Wpf/tests/Directory.Build.props
index 774158b0511..449882cbaab 100644
--- a/src/Microsoft.DotNet.Wpf/tests/Directory.Build.props
+++ b/src/Microsoft.DotNet.Wpf/tests/Directory.Build.props
@@ -1,7 +1,6 @@
- false
false
false
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/Directory.Build.targets b/src/Microsoft.DotNet.Wpf/tests/UnitTests/Directory.Build.targets
new file mode 100644
index 00000000000..911e37bda6e
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/Directory.Build.targets
@@ -0,0 +1,27 @@
+
+
+
+
+
+ <_PackagingNativePath Condition="'$(WpfRuntimeIdentifier)'=='win-x64' And '$(Configuration)' != 'Debug'">$(ArtifactsDir)packaging\$(Configuration)\x64\Microsoft.DotNet.Wpf.GitHub
+ <_PackagingNativePath Condition="'$(WpfRuntimeIdentifier)'=='win-x64' And '$(Configuration)' == 'Debug'">$(ArtifactsDir)packaging\$(Configuration)\x64\Microsoft.DotNet.Wpf.GitHub.Debug
+ <_PackagingNativePath Condition="'$(WpfRuntimeIdentifier)'=='win-x86' And '$(Configuration)' != 'Debug'">$(ArtifactsDir)packaging\$(Configuration)\Microsoft.DotNet.Wpf.GitHub
+ <_PackagingNativePath Condition="'$(WpfRuntimeIdentifier)'=='win-x86' And '$(Configuration)' == 'Debug'">$(ArtifactsDir)packaging\$(Configuration)\Microsoft.DotNet.Wpf.GitHub.Debug
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
index 1e670caed07..c20b096b1e1 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
@@ -5,26 +5,24 @@
true
true
enable
- net9.0-windows
- true
- AnyCPU;x64;x86
- True
+ AnyCPU;x64;x86;ARM64
true
-
-
+
+ TargetFramework;TargetFrameworks
+
+
+
-
-
-
+
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System.Xaml.Tests.csproj b/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System.Xaml.Tests.csproj
index 6e705cf75c8..28a2f211d4e 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System.Xaml.Tests.csproj
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System.Xaml.Tests.csproj
@@ -5,10 +5,11 @@
true
true
enable
+ AnyCPU;x64;x86;ARM64
-
+
From b3b6af90cca0ccc00a3ab4a1f27bfcb904ab209e Mon Sep 17 00:00:00 2001
From: Adam Sitnik
Date: Tue, 30 Jul 2024 10:06:41 +0200
Subject: [PATCH 2/3] Switch to System.Formats.Nrbf (#9465)
* install the System.Formats.Nrbf package
* switch to the new API
* remove unused methods
* remove everything related to parsing NRBF payloads and records that don't support writing
* try to fix and update the tests
* remove more unused code
Fixed conflict in Versions.props, and added missing entry to Version.Details.xml
---
eng/Version.Details.xml | 4 +
eng/Versions.props | 9 +-
.../PresentationCore/PresentationCore.csproj | 12 +-
.../System/Windows/BinaryFormat/ArrayInfo.cs | 7 -
.../Windows/BinaryFormat/ArraySingleObject.cs | 14 +-
.../BinaryFormat/ArraySinglePrimitive.cs | 18 +-
.../Windows/BinaryFormat/ArraySingleString.cs | 14 +-
.../Windows/BinaryFormat/BinaryArray.cs | 69 ---
.../Windows/BinaryFormat/BinaryArrayType.cs | 33 --
.../BinaryFormat/BinaryFormattedObject.cs | 81 ---
.../BinaryFormattedObjectExtensions.cs | 531 ------------------
.../Windows/BinaryFormat/BinaryLibrary.cs | 14 +-
.../BinaryFormat/BinaryObjectString.cs | 12 +-
.../BinaryFormat/BinaryReaderExtensions.cs | 57 --
.../System/Windows/BinaryFormat/ClassInfo.cs | 14 -
.../Windows/BinaryFormat/ClassRecord.cs | 7 -
.../Windows/BinaryFormat/ClassTypeInfo.cs | 5 -
.../Windows/BinaryFormat/ClassWithId.cs | 43 +-
.../Windows/BinaryFormat/ClassWithMembers.cs | 53 --
.../BinaryFormat/ClassWithMembersAndTypes.cs | 20 +-
.../System/Windows/BinaryFormat/Count.cs | 2 +
.../BinaryFormat/IBinaryFormatParseable.cs | 21 -
.../System/Windows/BinaryFormat/IRecord.cs | 7 -
.../System/Windows/BinaryFormat/Id.cs | 2 +
.../Windows/BinaryFormat/ListConverter.cs | 1 -
.../BinaryFormat/ListConverterHelper.cs | 33 --
.../BinaryFormat/MemberPrimitiveTyped.cs | 13 +-
.../Windows/BinaryFormat/MemberReference.cs | 6 +-
.../Windows/BinaryFormat/MemberTypeInfo.cs | 42 --
.../System/Windows/BinaryFormat/MessageEnd.cs | 8 +-
.../NullRecord.ObjectNullMultiple.cs | 8 +-
.../NullRecord.ObjectNullMultiple256.cs | 6 +-
.../System/Windows/BinaryFormat/NullRecord.cs | 2 +-
.../BinaryFormat/NullableAttributes.cs | 197 -------
.../System/Windows/BinaryFormat/ObjectNull.cs | 6 +-
.../System/Windows/BinaryFormat/Record.cs | 151 -----
.../System/Windows/BinaryFormat/RecordMap.cs | 22 -
.../BinaryFormat/SerializationExtensions.cs | 12 -
.../BinaryFormat/SerializationHeader.cs | 12 +-
.../BinaryFormat/SystemClassWithMembers.cs | 46 --
.../SystemClassWithMembersAndTypes.cs | 19 +-
.../System/Windows/BinaryFormat/TypeInfo.cs | 24 -
.../Nrbf/SerializationRecordExtensions.cs | 357 ++++++++++++
.../System/Windows/dataobject.cs | 3 +-
.../MS/Internal/DataStreams.cs | 8 +-
.../PresentationFramework.csproj | 1 +
.../BinaryFormat/ArrayTests.cs | 68 ---
.../BinaryFormat/BinaryFormatWriterTests.cs | 5 +-
.../BinaryFormattedObjectTests.cs | 414 --------------
.../BinaryFormat/ClassInfoTests.cs | 80 ---
.../BinaryFormat/ExceptionTests.cs | 67 ---
.../BinaryFormat/HashTableTests.cs | 40 +-
.../BinaryFormat/ListTests.cs | 101 +---
.../BinaryFormat/MemberTypeInfoTests.cs | 71 ---
.../BinaryFormat/PointFTests.cs | 31 -
.../BinaryFormat/PrimitiveTypeTests.cs | 80 ++-
.../BinaryFormat/RecordMapTests.cs | 30 -
.../BinaryFormat/SystemDrawingTests.cs | 53 +-
.../PresentationCore.Tests.csproj | 1 +
.../BinaryFormatTestExtensions.cs | 5 +-
60 files changed, 498 insertions(+), 2574 deletions(-)
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/BinaryArray.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/BinaryArrayType.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/BinaryFormattedObject.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/BinaryFormattedObjectExtensions.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/BinaryReaderExtensions.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ClassWithMembers.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/IBinaryFormatParseable.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/NullableAttributes.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/RecordMap.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/SystemClassWithMembers.cs
create mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Nrbf/SerializationRecordExtensions.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormattedObjectTests.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ClassInfoTests.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ExceptionTests.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/MemberTypeInfoTests.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PointFTests.cs
delete mode 100644 src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/RecordMapTests.cs
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index a45817485a8..ea63a63eccc 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -95,6 +95,10 @@
https://github.com/dotnet/runtime
bdcf3ef75e11d22e4973bf37f2d5b660b73aa266
+
+ https://github.com/dotnet/runtime
+ bdcf3ef75e11d22e4973bf37f2d5b660b73aa266
+
https://github.com/dotnet/runtime
bdcf3ef75e11d22e4973bf37f2d5b660b73aa266
diff --git a/eng/Versions.props b/eng/Versions.props
index 715134fb808..983745b1d9f 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -34,6 +34,7 @@
9.0.0-preview.7.24376.15
9.0.0-preview.7.24379.1
9.0.0-preview.7.24376.15
+ 9.0.0-preview.7.24376.15
9.0.0-preview.7.24376.15
9.0.0-preview.7.24376.15
4.6.0-preview4.19176.11
@@ -66,14 +67,14 @@
15.9.20
15.9.20
-
1.0.0-beta.19263.1
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
index 4572d7307cd..1dcab38bf60 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
@@ -338,19 +338,15 @@
-
-
-
-
-
+
@@ -366,19 +362,14 @@
-
-
-
-
-
@@ -1480,6 +1471,7 @@
+
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArrayInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArrayInfo.cs
index f041cebb1ee..fea38896b8a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArrayInfo.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArrayInfo.cs
@@ -26,13 +26,6 @@ public ArrayInfo(Id objectId, Count length)
ObjectId = objectId;
}
- public static ArrayInfo Parse(BinaryReader reader, out Count length)
- {
- ArrayInfo arrayInfo = new(reader.ReadInt32(), reader.ReadInt32());
- length = arrayInfo.Length;
- return arrayInfo;
- }
-
public readonly void Write(BinaryWriter writer)
{
writer.Write(ObjectId);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArraySingleObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArraySingleObject.cs
index 67212d7b576..ccb65ec4d24 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArraySingleObject.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/BinaryFormat/ArraySingleObject.cs
@@ -16,7 +16,7 @@ namespace System.Windows
///
///
///
- internal sealed class ArraySingleObject : ArrayRecord, IRecord
+ internal sealed class ArraySingleObject : ArrayRecord
{
public static RecordType RecordType => RecordType.ArraySingleObject;
@@ -24,18 +24,6 @@ public ArraySingleObject(ArrayInfo arrayInfo, IReadOnlyList
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ArrayTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ArrayTests.cs
index d188b4938df..695e7bb9ee8 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ArrayTests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ArrayTests.cs
@@ -1,68 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Collections;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Drawing;
-using System.IO;
-using FluentAssertions;
-using System.Threading;
-using System.Windows;
-using PresentationCore.Tests.TestUtilities;
-using PresentationCore.Tests.FluentAssertions;
-
namespace PresentationCore.Tests.BinaryFormat;
public class ArrayTests
{
- [Theory]
- [MemberData(nameof(ArrayInfo_ParseSuccessData))]
- public void ArrayInfo_Parse_Success(MemoryStream stream, int expectedId, int expectedLength)
- {
- using BinaryReader reader = new(stream);
- ArrayInfo info = ArrayInfo.Parse(reader, out Count length);
- info.ObjectId.Should().Be(expectedId);
- info.Length.Should().Be(expectedLength);
- length.Should().Be(expectedLength);
- }
-
- public static TheoryData ArrayInfo_ParseSuccessData => new()
- {
- { new MemoryStream(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }), 0, 0 },
- { new MemoryStream(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }), 1, 1 },
- { new MemoryStream(new byte[] { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }), 2, 1 },
- { new MemoryStream(new byte[] { 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F }), int.MaxValue, int.MaxValue }
- };
-
- [Theory]
- [MemberData(nameof(ArrayInfo_ParseNegativeData))]
- public void ArrayInfo_Parse_Negative(MemoryStream stream, Type expectedException)
- {
- using BinaryReader reader = new(stream);
- Assert.Throws(expectedException, () => ArrayInfo.Parse(reader, out Count length));
- }
-
- public static TheoryData ArrayInfo_ParseNegativeData => new()
- {
- // Not enough data
- { new MemoryStream(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }), typeof(EndOfStreamException) },
- { new MemoryStream(new byte[] { 0x00, 0x00, 0x00 }), typeof(EndOfStreamException) },
- // Negative numbers
- { new MemoryStream(new byte[] { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF }), typeof(ArgumentOutOfRangeException) }
- };
-
- [Theory]
- [MemberData(nameof(StringArray_Parse_Data))]
- public void StringArray_Parse(string?[] strings)
- {
- BinaryFormattedObject format = strings.SerializeAndParse();
- format.RecordCount.Should().BeGreaterThanOrEqualTo(3);
- ArraySingleString array = (ArraySingleString)format[1];
- format.GetStringValues(array, strings.Length).Should().BeEquivalentTo(strings);
- }
-
public static TheoryData StringArray_Parse_Data => new()
{
new string?[] { "one", "two" },
@@ -70,16 +12,6 @@ public void StringArray_Parse(string?[] strings)
new string?[] { "same", "same", "same" }
};
- [Theory]
- [MemberData(nameof(PrimitiveArray_Parse_Data))]
- public void PrimitiveArray_Parse(Array array)
- {
- BinaryFormattedObject format = array.SerializeAndParse();
- format.RecordCount.Should().BeGreaterThanOrEqualTo(3);
- ArraySinglePrimitive arrayRecord = (ArraySinglePrimitive)format[1];
- ((IEnumerable)arrayRecord.ArrayObjects).Should().BeEquivalentTo((IEnumerable)array);
- }
-
public static TheoryData PrimitiveArray_Parse_Data => new()
{
new int[] { 1, 2, 3 },
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormatWriterTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormatWriterTests.cs
index 342a28b21ee..1965b78edbd 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormatWriterTests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormatWriterTests.cs
@@ -6,6 +6,7 @@
using System.Runtime.Serialization.Formatters.Binary;
using PresentationCore.Tests.TestUtilities;
using PresentationCore.Tests.FluentAssertions;
+using System.Formats.Nrbf;
namespace PresentationCore.Tests.BinaryFormat;
@@ -71,7 +72,7 @@ public void BinaryFormatWriter_TryWriteObject_SupportedObjects_RoundTrip(object
BinaryFormatWriter.TryWriteFrameworkObject(stream, value).Should().BeTrue();
stream.Position = 0;
- BinaryFormattedObject format = new(stream);
+ SerializationRecord format = NrbfDecoder.Decode(stream);
format.TryGetFrameworkObject(out object? deserialized).Should().BeTrue();
if (value is Hashtable hashtable)
@@ -115,4 +116,4 @@ public void BinaryFormatWriter_TryWriteObject_UnsupportedObjects_RoundTrip(objec
ListTests.Lists_UnsupportedTestData).Concat(
ListTests.ArrayLists_UnsupportedTestData).Concat(
ArrayTests.Array_UnsupportedTestData);
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormattedObjectTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormattedObjectTests.cs
deleted file mode 100644
index 041168b5fff..00000000000
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/BinaryFormattedObjectTests.cs
+++ /dev/null
@@ -1,414 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Collections;
-using PresentationCore.Tests.TestUtilities;
-
-namespace PresentationCore.Tests.BinaryFormat;
-
-public class BinaryFormattedObjectTests
-{
- [Fact]
- public void ReadHeader()
- {
- BinaryFormattedObject format = "Hello World.".SerializeAndParse();
- SerializationHeader header = (SerializationHeader)format[0];
- header.MajorVersion.Should().Be(1);
- header.MinorVersion.Should().Be(0);
- header.RootId.Should().Be(1);
- header.HeaderId.Should().Be(-1);
- }
-
- [Theory]
- [InlineData("Hello there.")]
- [InlineData("")]
- [InlineData("Embedded\0 Null.")]
- public void ReadBinaryObjectString(string testString)
- {
- BinaryFormattedObject format = testString.SerializeAndParse();
- BinaryObjectString stringRecord = (BinaryObjectString)format[1];
- stringRecord.ObjectId.Should().Be(1);
- stringRecord.Value.Should().Be(testString);
- }
-
- [Fact]
- public void ReadEmptyHashTable()
- {
- BinaryFormattedObject format = new Hashtable().SerializeAndParse();
-
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
- systemClass.ObjectId.Should().Be(1);
- systemClass.Name.Should().Be("System.Collections.Hashtable");
- systemClass.MemberNames.Should().BeEquivalentTo(new[]
- {
- "LoadFactor",
- "Version",
- "Comparer",
- "HashCodeProvider",
- "HashSize",
- "Keys",
- "Values"
- });
-
- systemClass.MemberTypeInfo.Should().BeEquivalentTo(new (BinaryType Type, object? Info)[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.SystemClass, "System.Collections.IComparer"),
- (BinaryType.SystemClass, "System.Collections.IHashCodeProvider"),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.ObjectArray, null),
- (BinaryType.ObjectArray, null)
- });
-
- systemClass.MemberValues.Should().BeEquivalentTo(new object?[]
- {
- 0.72f,
- 0,
- ObjectNull.Instance,
- ObjectNull.Instance,
- 3,
- new MemberReference(2),
- new MemberReference(3)
- });
-
- ArraySingleObject array = (ArraySingleObject)format[2];
- array.ArrayInfo.ObjectId.Should().Be(2);
- array.ArrayInfo.Length.Should().Be(0);
-
- array = (ArraySingleObject)format[3];
- array.ArrayInfo.ObjectId.Should().Be(3);
- array.ArrayInfo.Length.Should().Be(0);
- }
-
- [Fact]
- public void ReadHashTableWithStringPair()
- {
- BinaryFormattedObject format = new Hashtable()
- {
- { "This", "That" }
- }.SerializeAndParse();
-
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
-
- systemClass.MemberTypeInfo.Should().BeEquivalentTo(new (BinaryType Type, object? Info)[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.SystemClass, "System.Collections.IComparer"),
- (BinaryType.SystemClass, "System.Collections.IHashCodeProvider"),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.ObjectArray, null),
- (BinaryType.ObjectArray, null)
- });
-
- systemClass.MemberValues.Should().BeEquivalentTo(new object?[]
- {
- 0.72f,
- 1,
- ObjectNull.Instance,
- ObjectNull.Instance,
- 3,
- new MemberReference(2),
- new MemberReference(3)
- });
-
- ArraySingleObject array = (ArraySingleObject)format[2];
- array.ArrayInfo.ObjectId.Should().Be(2);
- array.ArrayInfo.Length.Should().Be(1);
- BinaryObjectString value = (BinaryObjectString)array.ArrayObjects[0];
- value.ObjectId.Should().Be(4);
- value.Value.Should().Be("This");
-
- array = (ArraySingleObject)format[3];
- array.ArrayInfo.ObjectId.Should().Be(3);
- array.ArrayInfo.Length.Should().Be(1);
- value = (BinaryObjectString)array.ArrayObjects[0];
- value.ObjectId.Should().Be(5);
- value.Value.Should().Be("That");
- }
-
- [Fact]
- public void ReadHashTableWithRepeatedStrings()
- {
- BinaryFormattedObject format = new Hashtable()
- {
- { "This", "That" },
- { "TheOther", "This" },
- { "That", "This" }
- }.SerializeAndParse();
-
- // The collections themselves get ids first before the strings do.
- // Everything in the second array is a string reference.
- ArraySingleObject array = (ArraySingleObject)format[3];
- array.ObjectId.Should().Be(3);
- array[0].Should().BeOfType();
- array[1].Should().BeOfType();
- array[2].Should().BeOfType();
- }
-
- [Fact]
- public void ReadHashTableWithNullValues()
- {
- BinaryFormattedObject format = new Hashtable()
- {
- { "Yowza", null },
- { "Youza", null },
- { "Meeza", null }
- }.SerializeAndParse();
-
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
-
- systemClass.MemberValues.Should().BeEquivalentTo(new object?[]
- {
- 0.72f,
- 4,
- ObjectNull.Instance,
- ObjectNull.Instance,
- 7,
- new MemberReference(2),
- new MemberReference(3)
- });
-
- ArrayRecord array = (ArrayRecord)format[(MemberReference)systemClass.MemberValues[5]];
-
- array.ArrayInfo.ObjectId.Should().Be(2);
- array.ArrayInfo.Length.Should().Be(3);
- BinaryObjectString value = (BinaryObjectString)array.ArrayObjects[0];
- value.ObjectId.Should().Be(4);
- value.Value.Should().BeOneOf("Yowza", "Youza", "Meeza");
-
- array = (ArrayRecord)format[(MemberReference)systemClass["Values"]];
- array.ArrayInfo.ObjectId.Should().Be(3);
- array.ArrayInfo.Length.Should().Be(3);
- array.ArrayObjects[0].Should().BeOfType();
- }
-
- [Fact]
- public void ReadObject()
- {
- BinaryFormattedObject format = new object().SerializeAndParse();
- format[1].Should().BeOfType();
- }
-
- [Fact]
- public void ReadStruct()
- {
- ValueTuple tuple = new(355);
- BinaryFormattedObject format = tuple.SerializeAndParse();
- format[1].Should().BeOfType();
- }
-
- [Fact]
- public void ReadSimpleSerializableObject()
- {
- BinaryFormattedObject format = new SimpleSerializableObject().SerializeAndParse();
-
- BinaryLibrary library = (BinaryLibrary)format[1];
- library.LibraryName.Should().Be(typeof(BinaryFormattedObjectTests).Assembly.FullName);
- library.LibraryId.Should().Be(2);
-
- ClassWithMembersAndTypes @class = (ClassWithMembersAndTypes)format[2];
- @class.ObjectId.Should().Be(1);
- @class.Name.Should().Be(typeof(SimpleSerializableObject).FullName);
- @class.MemberNames.Should().BeEmpty();
- @class.LibraryId.Should().Be(2);
- @class.MemberTypeInfo.Should().BeEmpty();
-
- format[3].Should().BeOfType();
- }
-
- [Fact]
- public void ReadNestedSerializableObject()
- {
- BinaryFormattedObject format = new NestedSerializableObject().SerializeAndParse();
-
- BinaryLibrary library = (BinaryLibrary)format[1];
- library.LibraryName.Should().Be(typeof(BinaryFormattedObjectTests).Assembly.FullName);
- library.LibraryId.Should().Be(2);
-
- ClassWithMembersAndTypes @class = (ClassWithMembersAndTypes)format[2];
- @class.ObjectId.Should().Be(1);
- @class.Name.Should().Be(typeof(NestedSerializableObject).FullName);
- @class.MemberNames.Should().BeEquivalentTo(new[] { "_object", "_meaning" });
- @class.LibraryId.Should().Be(2);
- @class.MemberTypeInfo.Should().BeEquivalentTo(new (BinaryType Type, object? Info)[]
- {
- (BinaryType.Class, new ClassTypeInfo(typeof(SimpleSerializableObject).FullName!, 2)),
- (BinaryType.Primitive, PrimitiveType.Int32)
- });
- @class.MemberValues.Should().BeEquivalentTo(new object?[]
- {
- new MemberReference(3),
- 42
- });
-
- @class = (ClassWithMembersAndTypes)format[3];
- @class.ObjectId.Should().Be(3);
- @class.Name.Should().Be(typeof(SimpleSerializableObject).FullName);
- @class.MemberNames.Should().BeEmpty();
- @class.LibraryId.Should().Be(2);
- @class.MemberTypeInfo.Should().BeEmpty();
-
- format[4].Should().BeOfType();
- }
-
- [Fact]
- public void ReadTwoIntObject()
- {
- BinaryFormattedObject format = new TwoIntSerializableObject().SerializeAndParse();
-
- BinaryLibrary library = (BinaryLibrary)format[1];
- library.LibraryName.Should().Be(typeof(BinaryFormattedObjectTests).Assembly.FullName);
- library.LibraryId.Should().Be(2);
-
- ClassWithMembersAndTypes @class = (ClassWithMembersAndTypes)format[2];
- @class.ObjectId.Should().Be(1);
- @class.Name.Should().Be(typeof(TwoIntSerializableObject).FullName);
- @class.MemberNames.Should().BeEquivalentTo(new[] { "_value", "_meaning" });
- @class.LibraryId.Should().Be(2);
- @class.MemberTypeInfo.Should().BeEquivalentTo(new (BinaryType Type, object? Info)[]
- {
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.Primitive, PrimitiveType.Int32)
- });
-
- @class.MemberValues.Should().BeEquivalentTo(new object?[]
- {
- 1970,
- 42
- });
-
- format[3].Should().BeOfType();
- }
-
- [Fact]
- public void ReadRepeatedNestedObject()
- {
- BinaryFormattedObject format = new RepeatedNestedSerializableObject().SerializeAndParse();
- ClassWithMembersAndTypes firstClass = (ClassWithMembersAndTypes)format[3];
- ClassWithId classWithId = (ClassWithId)format[4];
- classWithId.MetadataId.Should().Be(firstClass.ObjectId);
- classWithId.MemberValues.Should().BeEquivalentTo(new object[] { 1970, 42 });
- }
-
- [Fact]
- public void ReadPrimitiveArray()
- {
- BinaryFormattedObject format = new int[] { 10, 9, 8, 7 }.SerializeAndParse();
-
- ArraySinglePrimitive array = (ArraySinglePrimitive)format[1];
- array.ArrayInfo.Length.Should().Be(4);
- array.PrimitiveType.Should().Be(PrimitiveType.Int32);
- array.ArrayObjects.Should().BeEquivalentTo(new object[] { 10, 9, 8, 7 });
- }
-
- [Fact]
- public void ReadStringArray()
- {
- BinaryFormattedObject format = new string[] { "Monday", "Tuesday", "Wednesday" }.SerializeAndParse();
- ArraySingleString array = (ArraySingleString)format[1];
- array.ArrayInfo.ObjectId.Should().Be(1);
- array.ArrayInfo.Length.Should().Be(3);
- BinaryObjectString value = (BinaryObjectString)array.ArrayObjects[0];
- }
-
- [Fact]
- public void ReadStringArrayWithNulls()
- {
- BinaryFormattedObject format = new string?[] { "Monday", null, "Wednesday", null, null, null }.SerializeAndParse();
- ArraySingleString array = (ArraySingleString)format[1];
- array.ArrayInfo.ObjectId.Should().Be(1);
- array.ArrayInfo.Length.Should().Be(6);
- array.ArrayObjects.Should().BeEquivalentTo(new object?[]
- {
- new BinaryObjectString(2, "Monday"),
- ObjectNull.Instance,
- new BinaryObjectString(3, "Wednesday"),
- ObjectNull.Instance,
- ObjectNull.Instance,
- ObjectNull.Instance
- });
- BinaryObjectString value = (BinaryObjectString)array.ArrayObjects[0];
- }
-
- [Fact]
- public void ReadDuplicatedStringArray()
- {
- BinaryFormattedObject format = new string[] { "Monday", "Tuesday", "Monday" }.SerializeAndParse();
- ArraySingleString array = (ArraySingleString)format[1];
- array.ArrayInfo.ObjectId.Should().Be(1);
- array.ArrayInfo.Length.Should().Be(3);
- BinaryObjectString value = (BinaryObjectString)array.ArrayObjects[0];
- MemberReference reference = (MemberReference)array.ArrayObjects[2];
- reference.IdRef.Should().Be(value.ObjectId);
- }
-
- [Fact]
- public void ReadObjectWithNullableObjects()
- {
- BinaryFormattedObject format = new ObjectWithNullableObjects().SerializeAndParse();
- ClassWithMembersAndTypes classRecord = (ClassWithMembersAndTypes)format[2];
- BinaryLibrary library = (BinaryLibrary)format[classRecord.LibraryId];
- }
-
- [Fact]
- public void ReadNestedObjectWithNullableObjects()
- {
- BinaryFormattedObject format = new NestedObjectWithNullableObjects().SerializeAndParse();
- ClassWithMembersAndTypes classRecord = (ClassWithMembersAndTypes)format[2];
- BinaryLibrary library = (BinaryLibrary)format[classRecord.LibraryId];
- }
-
- [Serializable]
- private class SimpleSerializableObject
- {
- }
-
-#pragma warning disable IDE0052 // Remove unread private members
-#pragma warning disable IDE0051 // Remove unused private members
-#pragma warning disable CS0414 // Field is assigned but its value is never used
-#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value null
-#pragma warning disable CA1823 // Avoid unused private fields
- [Serializable]
- private class ObjectWithNullableObjects
- {
- public object? First;
- public object? Second;
- public object? Third;
- }
-
- [Serializable]
- private class NestedObjectWithNullableObjects
- {
- public ObjectWithNullableObjects? First;
- public ObjectWithNullableObjects? Second;
- public ObjectWithNullableObjects? Third = new();
- }
-
- [Serializable]
- private class NestedSerializableObject
- {
- private readonly SimpleSerializableObject _object = new();
- private readonly int _meaning = 42;
- }
-
- [Serializable]
- private class TwoIntSerializableObject
- {
- private readonly int _value = 1970;
- private readonly int _meaning = 42;
- }
-
- [Serializable]
- private class RepeatedNestedSerializableObject
- {
- private readonly TwoIntSerializableObject _first = new();
- private readonly TwoIntSerializableObject _second = new();
- }
-#pragma warning restore IDE0052 // Remove unread private members
-#pragma warning restore IDE0051 // Remove unused private members
-#pragma warning restore CS0414 // Field is assigned but its value is never used
-#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value null
-#pragma warning restore CA1823 // Avoid unused private fields
-}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ClassInfoTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ClassInfoTests.cs
deleted file mode 100644
index 3b67a86b265..00000000000
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ClassInfoTests.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using PresentationCore.Tests.TestUtilities;
-using PresentationCore.Tests.FluentAssertions;
-namespace PresentationCore.Tests.BinaryFormat;
-
-public class ClassInfoTests
-{
- private static readonly byte[] s_hashtableClassInfo = new byte[]
- {
- 0x01, 0x00, 0x00, 0x00, 0x1c, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f, 0x6c, 0x6c,
- 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x48, 0x61, 0x73, 0x68, 0x74, 0x61, 0x62, 0x6c,
- 0x65, 0x07, 0x00, 0x00, 0x00, 0x0a, 0x4c, 0x6f, 0x61, 0x64, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72,
- 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x08, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65,
- 0x72, 0x10, 0x48, 0x61, 0x73, 0x68, 0x43, 0x6f, 0x64, 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64,
- 0x65, 0x72, 0x08, 0x48, 0x61, 0x73, 0x68, 0x53, 0x69, 0x7a, 0x65, 0x04, 0x4b, 0x65, 0x79, 0x73,
- 0x06, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73
- };
-
- [Fact]
- public void ClassInfo_ReadHashtable()
- {
- using BinaryReader reader = new(new MemoryStream(s_hashtableClassInfo));
- ClassInfo info = ClassInfo.Parse(reader, out Count memberCount);
-
- memberCount.Should().Be(7);
- info.ObjectId.Should().Be(1);
- info.Name.Should().Be("System.Collections.Hashtable");
- info.MemberNames.Should().BeEquivalentTo(new[]
- {
- "LoadFactor",
- "Version",
- "Comparer",
- "HashCodeProvider",
- "HashSize",
- "Keys",
- "Values"
- });
- }
-
- [Fact]
- public void ClassInfo_Hashtable_RoundTrip()
- {
- using BinaryReader reader = new(new MemoryStream(s_hashtableClassInfo));
- ClassInfo info = ClassInfo.Parse(reader, out Count memberCount);
-
- MemoryStream stream = new();
- BinaryWriter writer = new(stream);
- info.Write(writer);
- stream.Position = 0;
-
- using BinaryReader reader2 = new(stream);
- info = ClassInfo.Parse(reader2, out memberCount);
-
- memberCount.Should().Be(7);
- info.ObjectId.Should().Be(1);
- info.Name.Should().Be("System.Collections.Hashtable");
- info.MemberNames.Should().BeEquivalentTo(new[]
- {
- "LoadFactor",
- "Version",
- "Comparer",
- "HashCodeProvider",
- "HashSize",
- "Keys",
- "Values"
- });
- }
-
- [Fact]
- public void MemberTypeInfo_ReadHashtable_TooShort()
- {
- MemoryStream stream = new(s_hashtableClassInfo);
- stream.SetLength(stream.Length - 1);
- using BinaryReader reader = new(stream);
- Action action = () => ClassInfo.Parse(reader, out _);
- action.Should().Throw();
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ExceptionTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ExceptionTests.cs
deleted file mode 100644
index f2b53b197bf..00000000000
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ExceptionTests.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Collections;
-using PresentationCore.Tests.TestUtilities;
-using PresentationCore.Tests.FluentAssertions;
-
-namespace PresentationCore.Tests.BinaryFormat;
-
-public class ExceptionTests
-{
- [Fact]
- public void NotSupportedException_Parse()
- {
- BinaryFormattedObject format = new NotSupportedException().SerializeAndParse();
- format.RecordCount.Should().Be(3);
- var systemClass = (SystemClassWithMembersAndTypes)format[1];
- systemClass.Name.Should().Be(typeof(NotSupportedException).FullName);
- systemClass.MemberNames.Should().BeEquivalentTo(new string[]
- {
- "ClassName",
- "Message",
- "Data",
- "InnerException",
- "HelpURL",
- "StackTraceString",
- "RemoteStackTraceString",
- "RemoteStackIndex",
- "ExceptionMethod",
- "HResult",
- "Source",
- "WatsonBuckets"
- });
-
- systemClass.MemberTypeInfo.Should().BeEquivalentTo(new (BinaryType, object?)[]
- {
- (BinaryType.String, null),
- (BinaryType.String, null),
- (BinaryType.SystemClass, typeof(IDictionary).FullName),
- (BinaryType.SystemClass, typeof(Exception).FullName),
- (BinaryType.String, null),
- (BinaryType.String, null),
- (BinaryType.String, null),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.String, null),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.String, null),
- (BinaryType.PrimitiveArray, PrimitiveType.Byte)
- });
-
- systemClass.MemberValues.Should().BeEquivalentTo(new object[]
- {
- new BinaryObjectString(2, "System.NotSupportedException"),
- new BinaryObjectString(3, "Specified method is not supported."),
- ObjectNull.Instance,
- ObjectNull.Instance,
- ObjectNull.Instance,
- ObjectNull.Instance,
- ObjectNull.Instance,
- 0,
- ObjectNull.Instance,
- unchecked((int)0x80131515),
- ObjectNull.Instance,
- ObjectNull.Instance
- });
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/HashTableTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/HashTableTests.cs
index e67fc257935..5113c08be0b 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/HashTableTests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/HashTableTests.cs
@@ -4,6 +4,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
+using System.Formats.Nrbf;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using PresentationCore.Tests.TestUtilities;
@@ -60,23 +61,6 @@ public void HashTable_GetObjectData()
enumerator.Current.Value.Should().BeEquivalentTo(new object[] { "That" });
}
- [Fact]
- public void HashTable_CustomComparer()
- {
- Hashtable hashtable = new(new CustomHashCodeProvider(), StringComparer.OrdinalIgnoreCase)
- {
- { "This", "That" }
- };
-
- BinaryFormattedObject format = hashtable.SerializeAndParse();
- format[1].Should().BeOfType();
- format[2].Should().BeOfType().Which.Name.Should().Be("System.Collections.Hashtable");
- format[3].Should().BeOfType().Which.Name.Should().Be("System.OrdinalComparer");
- format[4].Should().BeOfType().Which.Name.Should().Be("PresentationCore.Tests.BinaryFormat.HashtableTests+CustomHashCodeProvider");
- format[5].Should().BeOfType();
- format[6].Should().BeOfType();
- }
-
[Fact]
public void HashTable_CustomComparer_DoesNotRead()
{
@@ -85,8 +69,8 @@ public void HashTable_CustomComparer_DoesNotRead()
{ "This", "That" }
};
- BinaryFormattedObject format = hashtable.SerializeAndParse();
- format.TryGetPrimitiveHashtable(out Hashtable? deserialized).Should().BeFalse();
+ SerializationRecord format = hashtable.SerializeAndParse();
+ format.TryGetPrimitiveHashtable(out object? deserialized).Should().BeFalse();
deserialized.Should().BeNull();
}
@@ -144,13 +128,13 @@ public void BinaryFormatWriter_WriteUnsupportedHashtables(Hashtable hashtable)
[MemberData(nameof(Hashtables_TestData))]
public void BinaryFormattedObjectExtensions_TryGetPrimitiveHashtable(Hashtable hashtable)
{
- BinaryFormattedObject format = hashtable.SerializeAndParse();
- format.TryGetPrimitiveHashtable(out Hashtable? deserialized).Should().BeTrue();
+ SerializationRecord format = hashtable.SerializeAndParse();
+ format.TryGetPrimitiveHashtable(out object? deserialized).Should().BeTrue();
- deserialized!.Count.Should().Be(hashtable.Count);
+ ((Hashtable)deserialized!).Count.Should().Be(hashtable.Count);
foreach (object? key in hashtable.Keys)
{
- deserialized[key].Should().Be(hashtable[key]);
+ ((Hashtable)deserialized)[key].Should().Be(hashtable[key]);
}
}
@@ -162,12 +146,12 @@ public void RoundTripHashtables(Hashtable hashtable)
BinaryFormatWriter.WritePrimitiveHashtable(stream, hashtable);
stream.Position = 0;
- BinaryFormattedObject format = new(stream);
- format.TryGetPrimitiveHashtable(out Hashtable? deserialized).Should().BeTrue();
- deserialized!.Count.Should().Be(hashtable.Count);
+ SerializationRecord format = NrbfDecoder.Decode(stream);
+ format.TryGetPrimitiveHashtable(out object? deserialized).Should().BeTrue();
+ ((Hashtable)deserialized!).Count.Should().Be(hashtable.Count);
foreach (object? key in hashtable.Keys)
{
- deserialized[key].Should().Be(hashtable[key]);
+ ((Hashtable)deserialized)[key].Should().Be(hashtable[key]);
}
}
@@ -298,4 +282,4 @@ private static Hashtable MakeRepeatedHashtable(int countOfEntries, object? value
// public uint ToUInt32(object value) => throw new NotImplementedException();
// public ulong ToUInt64(object value) => throw new NotImplementedException();
// }
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ListTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ListTests.cs
index 536fb82a1b4..e8fa948b6b9 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ListTests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/ListTests.cs
@@ -9,63 +9,12 @@
using FluentAssertions;
using PresentationCore.Tests.TestUtilities;
using PresentationCore.Tests.FluentAssertions;
+using System.Formats.Nrbf;
namespace PresentationCore.Tests.BinaryFormat;
public class ListTests
{
- [Fact]
- public void BinaryFormattedObject_ParseEmptyArrayList()
- {
- BinaryFormattedObject format = new ArrayList().SerializeAndParse();
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
-
- systemClass.Name.Should().Be(typeof(ArrayList).FullName);
- systemClass.MemberNames.Should().BeEquivalentTo(new string[] { "_items", "_size", "_version" });
- systemClass.MemberTypeInfo[0].Should().Be((BinaryType.ObjectArray, null));
-
- format[2].Should().BeOfType();
- }
-
- [Theory]
- [MemberData(nameof(ArrayList_Primitive_Data))]
- public void BinaryFormattedObject_ParsePrimitivesArrayList(object value)
- {
- BinaryFormattedObject format = new ArrayList()
- {
- value
- }.SerializeAndParse();
-
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
-
- systemClass.Name.Should().Be(typeof(ArrayList).FullName);
- systemClass.MemberNames.Should().BeEquivalentTo(new string[] { "_items", "_size", "_version" });
- systemClass.MemberTypeInfo[0].Should().Be((BinaryType.ObjectArray, null));
-
- ArraySingleObject array = (ArraySingleObject)format[2];
- MemberPrimitiveTyped primitve = (MemberPrimitiveTyped)array[0];
- primitve.Value.Should().Be(value);
- }
-
- [Fact]
- public void BinaryFormattedObject_ParseStringArrayList()
- {
- BinaryFormattedObject format = new ArrayList()
- {
- "JarJar"
- }.SerializeAndParse();
-
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
-
- systemClass.Name.Should().Be(typeof(ArrayList).FullName);
- systemClass.MemberNames.Should().BeEquivalentTo(new string[] { "_items", "_size", "_version" });
- systemClass.MemberTypeInfo[0].Should().Be((BinaryType.ObjectArray, null));
-
- ArraySingleObject array = (ArraySingleObject)format[2];
- BinaryObjectString binaryString = (BinaryObjectString)array[0];
- binaryString.Value.Should().Be("JarJar");
- }
-
public static TheoryData ArrayList_Primitive_Data => new()
{
int.MaxValue,
@@ -123,50 +72,6 @@ public void BinaryFormattedObject_ParseStringArrayList()
}
};
- [Fact]
- public void BinaryFormattedObject_ParseEmptyIntList()
- {
- BinaryFormattedObject format = new List().SerializeAndParse();
- SystemClassWithMembersAndTypes classInfo = (SystemClassWithMembersAndTypes)format[1];
-
- // Note that T types are serialized as the mscorlib type.
- classInfo.Name.Should().Be(
- "System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]");
-
- classInfo.ClassInfo.MemberNames.Should().BeEquivalentTo(new string[]
- {
- "_items",
- // This is something that wouldn't be needed if List implemented ISerializable. If we format
- // we can save any extra unused array spots.
- "_size",
- // It is a bit silly that _version gets serialized, it's only use is as a check to see if
- // the collection is modified while it is being enumerated.
- "_version"
- });
- classInfo.MemberTypeInfo[0].Should().Be((BinaryType.PrimitiveArray, PrimitiveType.Int32));
- classInfo.MemberTypeInfo[1].Should().Be((BinaryType.Primitive, PrimitiveType.Int32));
- classInfo.MemberTypeInfo[2].Should().Be((BinaryType.Primitive, PrimitiveType.Int32));
- classInfo["_items"].Should().BeOfType();
- classInfo["_size"].Should().Be(0);
- classInfo["_version"].Should().Be(0);
-
- ArraySinglePrimitive array = (ArraySinglePrimitive)format[2];
- array.Length.Should().Be(0);
- }
-
- [Fact]
- public void BinaryFormattedObject_ParseEmptyStringList()
- {
- BinaryFormattedObject format = new List().SerializeAndParse();
- SystemClassWithMembersAndTypes classInfo = (SystemClassWithMembersAndTypes)format[1];
- classInfo.ClassInfo.Name.Should().StartWith("System.Collections.Generic.List`1[[System.String,");
- classInfo.MemberTypeInfo[0].Should().Be((BinaryType.StringArray, null));
- classInfo["_items"].Should().BeOfType();
-
- ArraySingleString array = (ArraySingleString)format[2];
- array.Length.Should().Be(0);
- }
-
[Theory]
[MemberData(nameof(PrimitiveLists_TestData))]
public void BinaryFormatWriter_TryWritePrimitiveList(IList list)
@@ -197,7 +102,7 @@ public void BinaryFormatWriter_TryWritePrimitiveList_Unsupported(IList list)
[MemberData(nameof(PrimitiveLists_TestData))]
public void BinaryFormattedObjectExtensions_TryGetPrimitiveList(IList list)
{
- BinaryFormattedObject format = list.SerializeAndParse();
+ SerializationRecord format = list.SerializeAndParse();
format.TryGetPrimitiveList(out object? deserialized).Should().BeTrue();
deserialized.Should().BeEquivalentTo(list);
}
@@ -223,4 +128,4 @@ public void BinaryFormattedObjectExtensions_TryGetPrimitiveList(IList list)
new List(),
new List<(int, int)>()
};
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/MemberTypeInfoTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/MemberTypeInfoTests.cs
deleted file mode 100644
index bfd882a95fa..00000000000
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/MemberTypeInfoTests.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using PresentationCore.Tests.TestUtilities;
-
-namespace PresentationCore.Tests.BinaryFormat;
-
-public class MemberTypeInfoTests
-{
- private static readonly byte[] s_hashtableMemberInfo = new byte[]
- {
- 0x00, 0x00, 0x03, 0x03, 0x00, 0x05, 0x05, 0x0b, 0x08, 0x1c, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
- 0x2e, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x49, 0x43, 0x6f,
- 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72, 0x24, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43, 0x6f,
- 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x49, 0x48, 0x61, 0x73, 0x68, 0x43,
- 0x6f, 0x64, 0x65, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x08
- };
-
- [Fact]
- public void MemberTypeInfo_ReadHashtable()
- {
- using BinaryReader reader = new(new MemoryStream(s_hashtableMemberInfo));
- MemberTypeInfo info = MemberTypeInfo.Parse(reader, 7);
-
- info.Should().BeEquivalentTo(new (BinaryType Type, object? Info)[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.SystemClass, "System.Collections.IComparer"),
- (BinaryType.SystemClass, "System.Collections.IHashCodeProvider"),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.ObjectArray, null),
- (BinaryType.ObjectArray, null)
- });
- }
-
- [Fact]
- public void MemberTypeInfo_HashtableRoundTrip()
- {
- using BinaryReader reader = new(new MemoryStream(s_hashtableMemberInfo));
- MemberTypeInfo info = MemberTypeInfo.Parse(reader, 7);
-
- MemoryStream stream = new();
- BinaryWriter writer = new(stream);
- info.Write(writer);
- stream.Position = 0;
-
- using BinaryReader reader2 = new(stream);
- info = MemberTypeInfo.Parse(reader2, 7);
- info.Should().BeEquivalentTo(new (BinaryType Type, object? Info)[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.SystemClass, "System.Collections.IComparer"),
- (BinaryType.SystemClass, "System.Collections.IHashCodeProvider"),
- (BinaryType.Primitive, PrimitiveType.Int32),
- (BinaryType.ObjectArray, null),
- (BinaryType.ObjectArray, null)
- });
- }
-
- [Fact]
- public void MemberTypeInfo_ReadHashtable_TooShort()
- {
- MemoryStream stream = new(s_hashtableMemberInfo);
- stream.SetLength(stream.Length - 1);
- using BinaryReader reader = new(stream);
- Action action = () => MemberTypeInfo.Parse(reader, 7);
- action.Should().Throw();
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PointFTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PointFTests.cs
deleted file mode 100644
index d80e85862f0..00000000000
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PointFTests.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Drawing;
-using PresentationCore.Tests.TestUtilities;
-
-namespace PresentationCore.Tests.BinaryFormat;
-
-public class PointFTests
-{
- [Fact]
- public void PointF_Parse()
- {
- BinaryFormattedObject format = new PointF().SerializeAndParse();
-
- BinaryLibrary binaryLibrary = (BinaryLibrary)format[1];
- binaryLibrary.LibraryId.Should().Be(2);
- binaryLibrary.LibraryName.Should().Be("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
-
- ClassWithMembersAndTypes classInfo = (ClassWithMembersAndTypes)format[2];
- classInfo.ObjectId.Should().Be(1);
- classInfo.Name.Should().Be("System.Drawing.PointF");
- classInfo.MemberNames.Should().BeEquivalentTo(new string[] { "x", "y" });
- classInfo.MemberValues.Should().BeEquivalentTo(new object[] { 0.0f, 0.0f });
- classInfo.MemberTypeInfo.Should().BeEquivalentTo(new[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Single)
- });
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PrimitiveTypeTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PrimitiveTypeTests.cs
index d9042f33753..da83b1c030f 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PrimitiveTypeTests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/PrimitiveTypeTests.cs
@@ -8,6 +8,9 @@
using FluentAssertions;
using System.IO;
using PresentationCore.Tests.TestUtilities;
+using System.Globalization;
+using System.Runtime.Serialization;
+using System.Runtime.CompilerServices;
namespace PresentationCore.Tests.BinaryFormat;
@@ -84,16 +87,6 @@ public void WriteReadPrimitiveValue_RoundTrip(byte type, object value)
{ (byte)PrimitiveType.DateTime, DateTime.MaxValue },
};
- [Theory]
- [MemberData(nameof(Primitive_Data))]
- public void PrimitiveTypeMemberName(object value)
- {
- BinaryFormattedObject format = value.SerializeAndParse();
- SystemClassWithMembersAndTypes systemClass = (SystemClassWithMembersAndTypes)format[1];
- systemClass.MemberNames[0].Should().Be("m_value");
- systemClass.MemberValues.Count.Should().Be(1);
- }
-
[Theory]
[MemberData(nameof(Primitive_Data))]
[MemberData(nameof(Primitive_ExtendedData))]
@@ -111,16 +104,6 @@ public void BinaryFormatWriter_WritePrimitive(object value)
deserialized.Should().Be(value);
}
- [Theory]
- [MemberData(nameof(Primitive_Data))]
- [MemberData(nameof(Primitive_ExtendedData))]
- public void BinaryFormattedObject_ReadPrimitive(object value)
- {
- BinaryFormattedObject formattedObject = value.SerializeAndParse();
- formattedObject.TryGetPrimitiveType(out object? deserialized).Should().BeTrue();
- deserialized.Should().Be(value);
- }
-
public static TheoryData Primitive_Data => new()
{
int.MaxValue,
@@ -153,11 +136,64 @@ public static void WritePrimitiveValue(BinaryWriter writer, PrimitiveType type,
=> WritePrimitiveType(writer, type, value);
public static object ReadPrimitiveValue(BinaryReader reader, PrimitiveType type)
- => ReadPrimitiveType(reader, type);
+ => type switch
+ {
+ PrimitiveType.Boolean => reader.ReadBoolean(),
+ PrimitiveType.Byte => reader.ReadByte(),
+ PrimitiveType.SByte => reader.ReadSByte(),
+ PrimitiveType.Char => reader.ReadChar(),
+ PrimitiveType.Int16 => reader.ReadInt16(),
+ PrimitiveType.UInt16 => reader.ReadUInt16(),
+ PrimitiveType.Int32 => reader.ReadInt32(),
+ PrimitiveType.UInt32 => reader.ReadUInt32(),
+ PrimitiveType.Int64 => reader.ReadInt64(),
+ PrimitiveType.UInt64 => reader.ReadUInt64(),
+ PrimitiveType.Single => reader.ReadSingle(),
+ PrimitiveType.Double => reader.ReadDouble(),
+ PrimitiveType.Decimal => decimal.Parse(reader.ReadString(), CultureInfo.InvariantCulture),
+ PrimitiveType.DateTime => ReadDateTime(reader),
+ PrimitiveType.TimeSpan => new TimeSpan(reader.ReadInt64()),
+ // String is handled with a record, never on it's own
+ _ => throw new SerializationException($"Failure trying to read primitve '{type}'"),
+ };
+
+ ///
+ /// Reads a binary formatted from the given .
+ ///
+ /// The data was invalid.
+ private static unsafe DateTime ReadDateTime(BinaryReader reader)
+ => CreateDateTimeFromData(reader.ReadInt64());
+
+ ///
+ /// Creates a object from raw data with validation.
+ ///
+ /// was invalid.
+ private static DateTime CreateDateTimeFromData(long data)
+ {
+ // Copied from System.Runtime.Serialization.Formatters.Binary.BinaryParser
+
+ // Use DateTime's public constructor to validate the input, but we
+ // can't return that result as it strips off the kind. To address
+ // that, store the value directly into a DateTime via an unsafe cast.
+ // See BinaryFormatterWriter.WriteDateTime for details.
+
+ try
+ {
+ const long TicksMask = 0x3FFFFFFFFFFFFFFF;
+ _ = new DateTime(data & TicksMask);
+ }
+ catch (ArgumentException ex)
+ {
+ // Bad data
+ throw new SerializationException(ex.Message, ex);
+ }
+
+ return Unsafe.As(ref data);
+ }
public override void Write(BinaryWriter writer)
{
throw new NotImplementedException();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/RecordMapTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/RecordMapTests.cs
deleted file mode 100644
index 061e2a7925e..00000000000
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/RecordMapTests.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using PresentationCore.Tests.TestUtilities;
-
-namespace PresentationCore.Tests.BinaryFormat;
-
-public class RecordMapTests
-{
- private class Record : IRecord
- {
- void IBinaryWriteable.Write(BinaryWriter writer) { }
- }
-
- [Fact]
- public void RecordMap_CannotAddSameIndexTwice()
- {
- RecordMap map = new();
- Action action = () => map[1] = new Record();
- action();
- action.Should().Throw();
- }
-
- [Fact]
- public void RecordMap_GetMissingThrowsKeyNotFound()
- {
- RecordMap map = new();
- Func func = () => map[0];
- func.Should().Throw();
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/SystemDrawingTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/SystemDrawingTests.cs
index 123b3577de2..7ef30fc027a 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/SystemDrawingTests.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/BinaryFormat/SystemDrawingTests.cs
@@ -4,6 +4,7 @@
using System.Drawing;
using PresentationCore.Tests.TestUtilities;
using PresentationCore.Tests.FluentAssertions;
+using System.Formats.Nrbf;
namespace PresentationCore.Tests.BinaryFormat;
@@ -12,45 +13,27 @@ public class SystemDrawingTests
[Fact]
public void PointF_Parse()
{
- BinaryFormattedObject format = new PointF().SerializeAndParse();
-
- BinaryLibrary binaryLibrary = (BinaryLibrary)format[1];
- binaryLibrary.LibraryId.Should().Be(2);
- binaryLibrary.LibraryName.ToString().Should().Be("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
-
- ClassWithMembersAndTypes classInfo = (ClassWithMembersAndTypes)format[2];
- classInfo.ObjectId.Should().Be(1);
- classInfo.Name.Should().Be("System.Drawing.PointF");
- classInfo.MemberNames.Should().BeEquivalentTo(new string[] { "x", "y" });
- classInfo.MemberValues.Should().BeEquivalentTo(new object[] { 0.0f, 0.0f });
- classInfo.MemberTypeInfo.Should().BeEquivalentTo(new[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Single)
- });
+ PointF input = new(1.5f, 2.1f);
+ SerializationRecord record = input.SerializeAndParse();
+
+ Assert.True(record.TryGetPointF(out object? read));
+
+ Assert.Equal(input.X, ((PointF)read!).X);
+ Assert.Equal(input.Y, ((PointF)read).Y);
}
[Fact]
public void RectangleF_Parse()
{
- BinaryFormattedObject format = new RectangleF().SerializeAndParse();
-
- BinaryLibrary binaryLibrary = (BinaryLibrary)format[1];
- binaryLibrary.LibraryId.Should().Be(2);
- binaryLibrary.LibraryName.ToString().Should().Be("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
-
- ClassWithMembersAndTypes classInfo = (ClassWithMembersAndTypes)format[2];
- classInfo.ObjectId.Should().Be(1);
- classInfo.Name.Should().Be("System.Drawing.RectangleF");
- classInfo.MemberNames.Should().BeEquivalentTo(new string[] { "x", "y", "width", "height" });
- classInfo.MemberValues.Should().BeEquivalentTo(new object[] { 0.0f, 0.0f, 0.0f, 0.0f });
- classInfo.MemberTypeInfo.Should().BeEquivalentTo(new[]
- {
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Single),
- (BinaryType.Primitive, PrimitiveType.Single)
- });
+ RectangleF input = new(1.5f, 2.1f, 100.7f, 15.9f);
+ SerializationRecord record = input.SerializeAndParse();
+
+ Assert.True(record.TryGetRectangleF(out object? read));
+
+ Assert.Equal(input.X, ((RectangleF)read!).X);
+ Assert.Equal(input.Y, ((RectangleF)read).Y);
+ Assert.Equal(input.Width, ((RectangleF)read).Width);
+ Assert.Equal(input.Height, ((RectangleF)read).Height);
}
public static TheoryData SystemDrawing_TestData => new()
@@ -58,4 +41,4 @@ public void RectangleF_Parse()
new PointF(),
new RectangleF()
};
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
index c20b096b1e1..edc1f9cffa0 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
@@ -23,6 +23,7 @@
+
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/TestUtilities/BinaryFormatTestExtensions.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/TestUtilities/BinaryFormatTestExtensions.cs
index 7927e10225f..06ff94533e3 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/TestUtilities/BinaryFormatTestExtensions.cs
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/TestUtilities/BinaryFormatTestExtensions.cs
@@ -7,6 +7,7 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows;
+using System.Formats.Nrbf;
namespace PresentationCore.Tests.TestUtilities;
@@ -15,7 +16,7 @@ internal static class BinaryFormatTestExtensions
///
/// Serializes the object using the and reads it into a .
///
- public static BinaryFormattedObject SerializeAndParse(this object source) => new(source.Serialize());
+ public static SerializationRecord SerializeAndParse(this object source) => NrbfDecoder.Decode(source.Serialize());
///
/// Serializes the object using the .
@@ -62,4 +63,4 @@ public static bool IsBinaryFormatted(this Type type)
return !((converter.CanConvertFrom(typeof(string)) && converter.CanConvertTo(typeof(string)))
|| (converter.CanConvertFrom(typeof(byte[])) && converter.CanConvertTo(typeof(byte[]))));
}
-}
\ No newline at end of file
+}
From 57a01ac2506f6b9d087133d89a08d0cb6fba4864 Mon Sep 17 00:00:00 2001
From: Eric StJohn
Date: Tue, 30 Jul 2024 12:51:35 -0700
Subject: [PATCH 3/3] Ensure WPF builds against framework SRSF version (#9492)
WPF was depending on the package version of
System.Runtime.Serialization.Formatters but never shipping it.
Instead WPF should depend on the built-in assembly version.
To do that we need to update the SDK version since WPF's vcxprojs don't
enable the nuget package targeting pack https://github.com/dotnet/wpf/issues/9490
---
eng/WpfArcadeSdk/tools/TestProjects.targets | 1 -
global.json | 4 ++--
.../src/PresentationCore/PresentationCore.csproj | 3 +--
.../src/PresentationCore/ref/PresentationCore-ref.csproj | 3 +--
.../src/PresentationFramework/PresentationFramework.csproj | 3 +--
.../ref/PresentationFramework-ref.csproj | 3 +--
src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj | 3 +--
.../src/System.Xaml/ref/System.Xaml-ref.csproj | 3 +--
.../PresentationCore.Tests/PresentationCore.Tests.csproj | 1 +
9 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/eng/WpfArcadeSdk/tools/TestProjects.targets b/eng/WpfArcadeSdk/tools/TestProjects.targets
index 2c8fd22bf80..8fdc440ae42 100644
--- a/eng/WpfArcadeSdk/tools/TestProjects.targets
+++ b/eng/WpfArcadeSdk/tools/TestProjects.targets
@@ -29,7 +29,6 @@
-
diff --git a/global.json b/global.json
index e1127c3c06f..94ae565be4d 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"tools": {
- "dotnet": "9.0.100-preview.5.24307.3",
+ "dotnet": "9.0.100-preview.6.24328.19",
"runtimes": {
"dotnet": [
"2.1.7",
@@ -16,7 +16,7 @@
"Microsoft.DotNet.Helix.Sdk": "9.0.0-beta.24368.9"
},
"sdk": {
- "version": "9.0.100-preview.5.24307.3"
+ "version": "9.0.100-preview.6.24328.19"
},
"native-tools": {
"strawberry-perl": "5.38.0.1",
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
index 1dcab38bf60..036da859299 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
@@ -1452,6 +1452,7 @@
+
@@ -1467,8 +1468,6 @@
-
-
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/ref/PresentationCore-ref.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/ref/PresentationCore-ref.csproj
index 80380ec2120..75d9e1c713d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/ref/PresentationCore-ref.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/ref/PresentationCore-ref.csproj
@@ -50,6 +50,7 @@
+
@@ -62,8 +63,6 @@
-
-
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj
index e5e20434592..6e84493822b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj
@@ -1406,6 +1406,7 @@
+
@@ -1450,8 +1451,6 @@
-
-
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework-ref.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework-ref.csproj
index def41db3429..b7ea8c46323 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework-ref.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework-ref.csproj
@@ -58,6 +58,7 @@
+
@@ -89,8 +90,6 @@
-
-
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj
index 73ce444dbb0..12c475845a1 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System.Xaml.csproj
@@ -111,6 +111,7 @@
+
@@ -121,8 +122,6 @@
-
-
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/ref/System.Xaml-ref.csproj b/src/Microsoft.DotNet.Wpf/src/System.Xaml/ref/System.Xaml-ref.csproj
index c125f185415..7498f329404 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/ref/System.Xaml-ref.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/ref/System.Xaml-ref.csproj
@@ -38,6 +38,7 @@
+
@@ -48,8 +49,6 @@
-
-
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
index edc1f9cffa0..06631a73c3a 100644
--- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/PresentationCore.Tests.csproj
@@ -24,6 +24,7 @@
+