From 84c4caec1d61234f282c97992acc6c1d0a86d1b4 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 24 Jun 2024 11:06:21 -0400 Subject: [PATCH] Added more TNEF tests --- UnitTests/Tnef/TnefNameIdTests.cs | 91 ++++++++++++++++++++++++++ UnitTests/Tnef/TnefPropertyTagTests.cs | 71 ++++++++++++++++++++ UnitTests/Tnef/TnefTests.cs | 32 --------- 3 files changed, 162 insertions(+), 32 deletions(-) create mode 100644 UnitTests/Tnef/TnefNameIdTests.cs create mode 100644 UnitTests/Tnef/TnefPropertyTagTests.cs diff --git a/UnitTests/Tnef/TnefNameIdTests.cs b/UnitTests/Tnef/TnefNameIdTests.cs new file mode 100644 index 0000000000..9953cd733e --- /dev/null +++ b/UnitTests/Tnef/TnefNameIdTests.cs @@ -0,0 +1,91 @@ +// +// TnefNameIdTests.cs +// +// Author: Jeffrey Stedfast +// +// Copyright (c) 2013-2024 .NET Foundation and Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +using MimeKit.Tnef; + +namespace UnitTests.Tnef { + [TestFixture] + public class TnefNameIdTests + { + [Test] + public void TestConstructors () + { + var guid = Guid.NewGuid (); + var tnef1 = new TnefNameId (guid, 17); + + Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Id), "Kind Id"); + Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid Id"); + Assert.That (tnef1.Id, Is.EqualTo (17), "Id"); + + tnef1 = new TnefNameId (guid, "name"); + Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Name), "Kind Name"); + Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid Name"); + Assert.That (tnef1.Name, Is.EqualTo ("name"), "Name"); + } + + [Test] + public void TestEqualityOfIdAndName () + { + var guid = Guid.NewGuid (); + var tnef1 = new TnefNameId (guid, 17); + var tnef2 = new TnefNameId (guid, "name"); + + Assert.That (tnef2.GetHashCode (), Is.Not.EqualTo (tnef1.GetHashCode ()), "GetHashCode Name vs Id"); + Assert.That (tnef2, Is.Not.EqualTo (tnef1), "Equal Name vs Id"); + + Assert.That (tnef1 == tnef2, Is.False, "=="); + Assert.That (tnef1 != tnef2, Is.True, "!="); + } + + [Test] + public void TestEqualityById () + { + var guid = Guid.NewGuid (); + var tnef1 = new TnefNameId (guid, 17); + var tnef2 = new TnefNameId (guid, 17); + + Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode"); + Assert.That (tnef2, Is.EqualTo (tnef1), "Equals"); + + Assert.That (tnef1 == tnef2, Is.True, "=="); + Assert.That (tnef1 != tnef2, Is.False, "!="); + } + + [Test] + public void TestEqualityByName () + { + var guid = Guid.NewGuid (); + var tnef1 = new TnefNameId (guid, "name"); + var tnef2 = new TnefNameId (guid, "name"); + + Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode"); + Assert.That (tnef2, Is.EqualTo (tnef1), "Equals"); + + Assert.That (tnef1 == tnef2, Is.True, "=="); + Assert.That (tnef1 != tnef2, Is.False, "!="); + } + } +} diff --git a/UnitTests/Tnef/TnefPropertyTagTests.cs b/UnitTests/Tnef/TnefPropertyTagTests.cs new file mode 100644 index 0000000000..359ece4729 --- /dev/null +++ b/UnitTests/Tnef/TnefPropertyTagTests.cs @@ -0,0 +1,71 @@ +// +// TnefPropertyTagTests.cs +// +// Author: Jeffrey Stedfast +// +// Copyright (c) 2013-2024 .NET Foundation and Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +using System.Reflection; + +using MimeKit.Tnef; + +namespace UnitTests.Tnef { + [TestFixture] + public class TnefPropertyTagTests + { + [Test] + public void TestBuiltIns () + { + foreach (var field in typeof (TnefPropertyTag).GetFields (BindingFlags.Public | BindingFlags.Static)) { + var propertyTag = (TnefPropertyTag) field.GetValue (null); + + Assert.That (propertyTag.IsTnefTypeValid, Is.True, $"{field.Name}.IsTnefTypeValid"); + + var tag = new TnefPropertyTag (propertyTag.Id, propertyTag.TnefType); + + Assert.That (tag.Id, Is.EqualTo (propertyTag.Id), $"{field.Name}.Id #1"); + Assert.That (tag.TnefType, Is.EqualTo (propertyTag.TnefType), $"{field.Name}.TnefType #1"); + Assert.That (tag.IsNamed, Is.EqualTo (propertyTag.IsNamed), $"{field.Name}.IsNamed #1"); + Assert.That (tag.IsMultiValued, Is.EqualTo (propertyTag.IsMultiValued), $"{field.Name}.IsMultiValued #1"); + Assert.That (tag.ValueTnefType, Is.EqualTo (propertyTag.ValueTnefType), $"{field.Name}.ValueTnefType #1"); + + Assert.That (tag.GetHashCode (), Is.EqualTo (propertyTag.GetHashCode ()), $"{field.Name}.GetHashCode #1"); + Assert.That (tag, Is.EqualTo (propertyTag), $"{field.Name}.Equals #1"); + Assert.That (tag == propertyTag, Is.True, $"{field.Name} == #1"); + Assert.That (tag != propertyTag, Is.False, $"{field.Name} != #1"); + + tag = new TnefPropertyTag ((int) propertyTag); + + Assert.That (tag.Id, Is.EqualTo (propertyTag.Id), $"{field.Name}.Id #2"); + Assert.That (tag.TnefType, Is.EqualTo (propertyTag.TnefType), $"{field.Name}.TnefType #2"); + Assert.That (tag.IsNamed, Is.EqualTo (propertyTag.IsNamed), $"{field.Name}.IsNamed #2"); + Assert.That (tag.IsMultiValued, Is.EqualTo (propertyTag.IsMultiValued), $"{field.Name}.IsMultiValued #2"); + Assert.That (tag.ValueTnefType, Is.EqualTo (propertyTag.ValueTnefType), $"{field.Name}.ValueTnefType #2"); + + Assert.That (tag.GetHashCode (), Is.EqualTo (propertyTag.GetHashCode ()), $"{field.Name}.GetHashCode #2"); + Assert.That (tag, Is.EqualTo (propertyTag), $"{field.Name}.Equals #2"); + Assert.That (tag == propertyTag, Is.True, $"{field.Name} == #2"); + Assert.That (tag != propertyTag, Is.False, $"{field.Name} != #2"); + } + } + } +} diff --git a/UnitTests/Tnef/TnefTests.cs b/UnitTests/Tnef/TnefTests.cs index cf7276915e..13e04c9a8e 100644 --- a/UnitTests/Tnef/TnefTests.cs +++ b/UnitTests/Tnef/TnefTests.cs @@ -1018,37 +1018,5 @@ public void TestRichTextEml () Assert.That (appointment2.ContentDisposition.ModificationDate, Is.EqualTo (mtime), "ModificationDate"); Assert.That (appointment2.ContentDisposition.Size, Is.EqualTo (387453), "Size"); } - - [Test] - public void TestTnefNameId () - { - var guid = Guid.NewGuid (); - var tnef1 = new TnefNameId (guid, 17); - var tnef2 = new TnefNameId (guid, 17); - - Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Id), "Kind Id"); - Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid Id"); - Assert.That (tnef1.Id, Is.EqualTo (17), "Id"); - - Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode Id"); - Assert.That (tnef2, Is.EqualTo (tnef1), "Equal Id"); - - tnef1 = new TnefNameId (guid, "name"); - Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Name), "Kind Name"); - Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid"); - Assert.That (tnef1.Name, Is.EqualTo ("name"), "Name"); - - Assert.That (tnef2.GetHashCode (), Is.Not.EqualTo (tnef1.GetHashCode ()), "GetHashCode Name vs Id"); - Assert.That (tnef2, Is.Not.EqualTo (tnef1), "Equal Name vs Id"); - - tnef2 = new TnefNameId (guid, "name"); - Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode Name"); - Assert.That (tnef2, Is.EqualTo (tnef1), "Equal Name"); - - Assert.That (tnef1.Equals (new object ()), Is.False, "Equals (object)"); - - Assert.That (tnef1 == tnef2, Is.True, "=="); - Assert.That (tnef1 != tnef2, Is.False, "!="); - } } }