From 19455499573f1c5e105f627c6a597f1cd142bdad Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Tue, 21 Sep 2021 01:14:46 +0700 Subject: [PATCH] System.Drawing.Common.Tests updated ConvertTo_String tests for null value --- .../tests/System/Drawing/IconConverterTests.cs | 10 +++++++++- .../tests/System/Drawing/ImageConverterTests.cs | 12 ++++++++++-- .../System/Drawing/ImageFormatConverterTests.cs | 7 +++++++ .../System/Drawing/Printing/MarginsConverterTests.cs | 4 ++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Drawing.Common/tests/System/Drawing/IconConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/IconConverterTests.cs index 2a4555226fecc..dab98748cd5ea 100644 --- a/src/libraries/System.Drawing.Common/tests/System/Drawing/IconConverterTests.cs +++ b/src/libraries/System.Drawing.Common/tests/System/Drawing/IconConverterTests.cs @@ -5,6 +5,7 @@ using System.Drawing.Imaging; using System.Globalization; using System.IO; +using System.Tests; using Xunit; namespace System.ComponentModel.TypeConverterTests @@ -171,7 +172,14 @@ public void TestConvertTo() Assert.Throws(() => _icoConvFrmTD.ConvertTo(null, CultureInfo.InvariantCulture, _icon, typeof(object))); Assert.Throws(() => _icoConvFrmTD.ConvertTo(null, CultureInfo.InvariantCulture, _icon, typeof(int))); - Assert.Equal("(none)", (string)_icoConv.ConvertTo(null, typeof(string))); + using (new ThreadCultureChange(CultureInfo.CreateSpecificCulture("fr-FR"), CultureInfo.InvariantCulture)) + { + Assert.Equal("(none)", (string)_icoConv.ConvertTo(null, typeof(string))); + Assert.Equal("(none)", (string)_icoConv.ConvertTo(null, CultureInfo.CreateSpecificCulture("ru-RU"), null, typeof(string))); + + Assert.Equal("(none)", (string)_icoConvFrmTD.ConvertTo(null, typeof(string))); + Assert.Equal("(none)", (string)_icoConvFrmTD.ConvertTo(null, CultureInfo.CreateSpecificCulture("de-DE"), null, typeof(string))); + } } } } diff --git a/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageConverterTests.cs index 5c0d29e4470fb..35688c6791d39 100644 --- a/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageConverterTests.cs +++ b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageConverterTests.cs @@ -5,6 +5,7 @@ using System.Drawing.Imaging; using System.Globalization; using System.IO; +using System.Tests; using Xunit; namespace System.ComponentModel.TypeConverterTests @@ -137,8 +138,6 @@ public void ConvertFrom() Assert.Equal(_image.Height, newImage.Height); Assert.Equal(_image.Width, newImage.Width); - Assert.Equal("(none)", _imgConvFrmTD.ConvertTo(null, CultureInfo.InvariantCulture, null, typeof(string))); - newImage = (Image)_imgConvFrmTD.ConvertFrom(null, CultureInfo.InvariantCulture, _imageBytes); Assert.Equal(_image.Height, newImage.Height); @@ -170,6 +169,15 @@ public void ConvertTo_String() Assert.Equal(_imageStr, (string)_imgConv.ConvertTo(_image, typeof(string))); Assert.Equal(_imageStr, (string)_imgConvFrmTD.ConvertTo(null, CultureInfo.InvariantCulture, _image, typeof(string))); Assert.Equal(_imageStr, (string)_imgConvFrmTD.ConvertTo(_image, typeof(string))); + + using (new ThreadCultureChange(CultureInfo.CreateSpecificCulture("fr-FR"), CultureInfo.InvariantCulture)) + { + Assert.Equal("(none)", (string)_imgConv.ConvertTo(null, typeof(string))); + Assert.Equal("(none)", (string)_imgConv.ConvertTo(null, CultureInfo.CreateSpecificCulture("ru-RU"), null, typeof(string))); + + Assert.Equal("(none)", (string)_imgConvFrmTD.ConvertTo(null, typeof(string))); + Assert.Equal("(none)", (string)_imgConvFrmTD.ConvertTo(null, CultureInfo.CreateSpecificCulture("de-DE"), null, typeof(string))); + } } [ConditionalFact(Helpers.IsDrawingSupported)] diff --git a/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs index 86eb901be192a..53963a1ee0257 100644 --- a/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs +++ b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageFormatConverterTests.cs @@ -5,6 +5,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.Globalization; +using System.Tests; using Xunit; namespace System.ComponentModel.TypeConverterTests @@ -132,6 +133,12 @@ public void TestConvertTo_String() Assert.Equal(_imageFmtStr, (string)_imgFmtConvFrmTD.ConvertTo(null, CultureInfo.InvariantCulture, _imageFmt, typeof(string))); Assert.Equal(_imageFmtStr, (string)_imgFmtConvFrmTD.ConvertTo(_imageFmt, typeof(string))); + + Assert.Equal(string.Empty, (string)_imgFmtConv.ConvertTo(null, typeof(string))); + Assert.Equal(string.Empty, (string)_imgFmtConv.ConvertTo(null, CultureInfo.CreateSpecificCulture("ru-RU"), null, typeof(string))); + + Assert.Equal(string.Empty, (string)_imgFmtConvFrmTD.ConvertTo(null, typeof(string))); + Assert.Equal(string.Empty, (string)_imgFmtConvFrmTD.ConvertTo(null, CultureInfo.CreateSpecificCulture("de-DE"), null, typeof(string))); } [ConditionalFact(Helpers.IsDrawingSupported)] diff --git a/src/libraries/System.Drawing.Common/tests/System/Drawing/Printing/MarginsConverterTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/Printing/MarginsConverterTests.cs index 019171ccdc36d..a9f68e05b98e5 100644 --- a/src/libraries/System.Drawing.Common/tests/System/Drawing/Printing/MarginsConverterTests.cs +++ b/src/libraries/System.Drawing.Common/tests/System/Drawing/Printing/MarginsConverterTests.cs @@ -6,6 +6,7 @@ using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Globalization; +using System.Tests; using Xunit; namespace System.Drawing.Printing.Tests @@ -139,6 +140,9 @@ public void ConvertTo() Assert.Throws(() => mc.ConvertTo(context, culture, new object(), typeof(object))); Assert.Throws(() => mc.ConvertTo(context, culture, 12, typeof(int))); Assert.Throws(() => mc.ConvertTo(context, culture, guid, typeof(Guid))); + + Assert.Equal(string.Empty, (string)mc.ConvertTo(null, typeof(string))); + Assert.Equal(string.Empty, (string)mc.ConvertTo(context, CultureInfo.CreateSpecificCulture("ru-RU"), null, typeof(string))); } }