Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2016-10-17 22:31:42 +0300
committerStephen Toub <stoub@microsoft.com>2016-10-18 06:26:40 +0300
commit6dec303efa455f9f20203fba3f1bc7085a1f7cfb (patch)
treeec8880377cec934455241563893163f31e109e78 /src/System.Drawing.Primitives/tests
parent729a009a02db761871bb4992b82bb850c26f68c7 (diff)
Add System.Drawing.Primitives serialization
Diffstat (limited to 'src/System.Drawing.Primitives/tests')
-rw-r--r--src/System.Drawing.Primitives/tests/ColorTests.cs15
-rw-r--r--src/System.Drawing.Primitives/tests/SerializationTests.cs65
-rw-r--r--src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj4
3 files changed, 69 insertions, 15 deletions
diff --git a/src/System.Drawing.Primitives/tests/ColorTests.cs b/src/System.Drawing.Primitives/tests/ColorTests.cs
index 198dcdc9a9..6453e579f4 100644
--- a/src/System.Drawing.Primitives/tests/ColorTests.cs
+++ b/src/System.Drawing.Primitives/tests/ColorTests.cs
@@ -512,21 +512,6 @@ namespace System.Drawing.Primitives.Tests
}
[Fact]
- public void SerializationRoundTrip()
- {
- Color c = Color.Red;
- CheckRed(c);
-
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream ms = new MemoryStream();
- bf.Serialize(ms, c);
-
- ms.Position = 0;
- Color color = (Color)bf.Deserialize(ms);
- CheckRed(color);
- }
-
- [Fact]
public void DebuggerAttributesAreValid()
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(Color.Aquamarine);
diff --git a/src/System.Drawing.Primitives/tests/SerializationTests.cs b/src/System.Drawing.Primitives/tests/SerializationTests.cs
new file mode 100644
index 0000000000..7bfd5fbc57
--- /dev/null
+++ b/src/System.Drawing.Primitives/tests/SerializationTests.cs
@@ -0,0 +1,65 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization.Formatters.Tests;
+using Xunit;
+
+namespace System.Drawing.Primitives.Tests
+{
+ public class SerializationTests
+ {
+ public static IEnumerable<object[]> Color_Roundtrip_MemberData()
+ {
+ yield return new object[] { default(Color) };
+ yield return new object[] { Color.FromKnownColor(KnownColor.AliceBlue) };
+ yield return new object[] { Color.AliceBlue };
+ yield return new object[] { Color.FromArgb(255, 1, 2, 3) };
+ yield return new object[] { Color.FromArgb(0, 1, 2, 3) };
+ yield return new object[] { Color.FromArgb(1, 2, 3) };
+ yield return new object[] { Color.FromName("SomeName") };
+ }
+
+ public static IEnumerable<object[]> Size_Roundtrip_MemberData()
+ {
+ yield return new object[] { new SizeF(123.4f, 567.8f) };
+ }
+
+ public static IEnumerable<object[]> Point_Roundtrip_MemberData()
+ {
+ yield return new object[] { new PointF(123.4f, 567.8f) };
+ }
+
+ public static IEnumerable<object[]> Rectangle_Roundtrip_MemberData()
+ {
+ yield return new object[] { new RectangleF(1.2f, 3.4f, 5.6f, 7.8f) };
+ }
+
+ [Theory]
+ [MemberData(nameof(Color_Roundtrip_MemberData))]
+ public void Color_Roundtrip(Color c) => Assert.Equal(c, BinaryFormatterHelpers.Clone(c));
+
+ [Theory]
+ [MemberData(nameof(Size_Roundtrip_MemberData))]
+ public void Size_Roundtrip(SizeF s)
+ {
+ Assert.Equal(s, BinaryFormatterHelpers.Clone(s));
+ Assert.Equal(s.ToSize(), BinaryFormatterHelpers.Clone(s.ToSize()));
+ }
+
+ [Theory]
+ [MemberData(nameof(Point_Roundtrip_MemberData))]
+ public void Point_Roundtrip(PointF p)
+ {
+ Assert.Equal(p, BinaryFormatterHelpers.Clone(p));
+ Assert.Equal(Point.Truncate(p), BinaryFormatterHelpers.Clone(Point.Truncate(p)));
+ }
+
+ [Theory]
+ [MemberData(nameof(Rectangle_Roundtrip_MemberData))]
+ public void Rectangle_Roundtrip(RectangleF r)
+ {
+ Assert.Equal(r, BinaryFormatterHelpers.Clone(r));
+ Assert.Equal(Rectangle.Truncate(r), BinaryFormatterHelpers.Clone(Rectangle.Truncate(r)));
+ }
+ }
+}
diff --git a/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj b/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj
index 666ce951ae..b3da4cd282 100644
--- a/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj
+++ b/src/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj
@@ -37,9 +37,13 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == ''">
<Compile Include="ColorTests.cs" />
+ <Compile Include="SerializationTests.cs" />
<Compile Include="$(CommonTestPath)\System\Diagnostics\DebuggerAttributes.cs">
<Link>Common\System\Diagnostics\DebuggerAttributes.cs</Link>
</Compile>
+ <Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
+ <Link>Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
+ </Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project> \ No newline at end of file