[main] Partial fix for AVAudioEngine.Connect(input, sink, format) crash when format == null (#9410)

* partial fix for https://github.com/xamarin/xamarin-macios/issues/9267

* simplify notequals

* add monotouch-test case

* add more using per manuel's feedback

Co-authored-by: Whitney Schmidt <whschm@microsoft.com>
This commit is contained in:
monojenkins 2020-08-20 07:41:42 -04:00 коммит произвёл GitHub
Родитель 558af9612a
Коммит 2a569e6274
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 59 добавлений и 1 удалений

Просмотреть файл

@ -21,12 +21,16 @@ namespace AVFoundation {
public partial class AVAudioFormat {
public static bool operator == (AVAudioFormat a, AVAudioFormat b)
{
if ((object) a == (object) b)
return true;
if ((object) a == null ^ (object) b == null)
return false;
return a.Equals (b);
}
public static bool operator != (AVAudioFormat a, AVAudioFormat b)
{
return !a.Equals (b);
return !(a == b);
}
}
}

Просмотреть файл

@ -0,0 +1,54 @@
// Unit test for AVAudioFormat
// Authors:
// Whitney Schmidt (whschm@microsoft.com)
// Copyright 2020 Microsoft Corp.
using System;
using Foundation;
using AVFoundation;
using NUnit.Framework;
namespace MonoTouchFixtures.AVFoundation {
[TestFixture]
[Preserve (AllMembers = true)]
public class AVAudioFormatTest {
[Test]
public void TestEqualOperatorSameInstace ()
{
using (var format = new AVAudioFormat ())
Assert.IsTrue (format == format, "format == format");
}
[Test]
public void TestEqualOperatorNull ()
{
using (var format = new AVAudioFormat ())
{
Assert.IsFalse (format == null, "format == null");
Assert.IsFalse (null == format, "null == format");
}
using (AVAudioFormat nullFormat = null)
{
Assert.IsTrue (nullFormat == null, "nullFormat == null");
Assert.IsTrue (null == nullFormat, "null == nullFormat");
}
}
[Test]
public void TestNotEqualOperatorNull ()
{
using (var format = new AVAudioFormat ())
{
Assert.IsTrue (format != null, "format != null");
Assert.IsTrue (null != format, "null != format");
}
using (AVAudioFormat nullFormat = null)
{
Assert.IsFalse (nullFormat != null, "nullFormat != null");
Assert.IsFalse (null != nullFormat, "null != nullFormat");
}
}
}
}