Skip to content

Commit

Permalink
Address reviews and add tests for manual code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Sep 1, 2021
1 parent 1da2f02 commit 94d8143
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/CoreVideo/CVBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using CoreFoundation;
using ObjCRuntime;
using Foundation;
Expand Down Expand Up @@ -150,9 +151,9 @@ public NSObject GetAttachment (NSString key, out CVAttachmentMode attachmentMode
if (key == null)
throw new ArgumentNullException ("key");
if (PlatformHelper.CheckSystemVersion (12, 0))
return Runtime.GetNSObject (CVBufferCopyAttachment (handle, key.Handle, out attachmentMode));
return Runtime.GetINativeObject<NSObject> (CVBufferCopyAttachment (handle, key.Handle, out attachmentMode), true);
else
return Runtime.GetNSObject (CVBufferGetAttachment (handle, key.Handle, out attachmentMode));
return Runtime.GetINativeObject<NSObject> (CVBufferGetAttachment (handle, key.Handle, out attachmentMode), false);
}
#endif

Expand All @@ -177,8 +178,8 @@ public NSDictionary GetAttachments (CVAttachmentMode attachmentMode)
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
return (NSDictionary) Runtime.GetNSObject (CVBufferCopyAttachments (handle, attachmentMode));
return (NSDictionary) Runtime.GetNSObject (CVBufferGetAttachments (handle, attachmentMode));
return Runtime.GetINativeObject<NSDictionary> (CVBufferCopyAttachments (handle, attachmentMode), true);
return Runtime.GetINativeObject<NSDictionary> (CVBufferGetAttachments (handle, attachmentMode), false);
}

// There is some API that needs a more strongly typed version of a NSDictionary
Expand Down Expand Up @@ -232,7 +233,7 @@ public void SetAttachments (NSDictionary theAttachments, CVAttachmentMode attach
[SupportedOSPlatform ("macos12.0")]
#endif
[DllImport (Constants.CoreVideoLibrary)]
[return: MarshalAs(UnmanagedType.U1)]
[return: MarshalAs (UnmanagedType.U1)]
static extern bool CVBufferHasAttachment (/* CVBufferRef */ IntPtr buffer, /* CFStringRef */ IntPtr key);

#if !NET
Expand Down
111 changes: 111 additions & 0 deletions tests/monotouch-test/CoreVideo/CVDisplayLinkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#if __MACOS__
using System;
using CoreGraphics;
using Foundation;
using NUnit.Framework;
using Foundation;
using ObjCRuntime;
using CoreVideo;

namespace MonoTouchFixtures.CoreVideo {

[TestFixture]
[Preserve (AllMembers = true)]
public class CVDisplayLinkTest {
int? mainDisplayId = null;

[SetUp]
public void SetUp ()
{
// we need to have access to the media display to be able to perform
// the displaylink tests
mainDisplayId = CGDisplay.MainDisplayID;
}

[TearDown]
public void TearDown ()
{
mainDisplayId = null;
}

[Test]
public void CreateFromDisplayIdValidIdTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromDisplayId ((uint) CGDisplay.MainDisplayID);
Assert.NotNull (displayLink, "Not null");
Assert.AreEqual (CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay (), "DisplayId");
}, "Throws");
}

[Test]
public void CreateFromDisplayWrongIdTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromDisplayId (UInt32.MaxValue);
Assert.Null (displayLink, "null");
}, "Throws");
}

[Test]
public void CreateFromDisplayIdsTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
// we might not have more than one display, therefore we will use an array
// with a single one, there is nothing in the docs that say that we cannot do that
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromDisplayIds (new []{ (uint) CGDisplay.MainDisplayID});
Assert.Null (displayLink, "null");
}, "Throws");
}

[Test]
public void CreateFromOpenGLMaskTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
var openGLMask = CGDisplay.GetOpenGLDisplayMask (CGDisplay.MainDisplayID);
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromOpenGLMask ((uint) openGLMask);
Assert.NotNull (displayLink, "Not null");
}, "Throws");
}

[Test]
public void DefaultconstructorTest () => Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
});

[Test]
public void SetCurrentDisplayOpenGLTest () => Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
displayLink.SetCurrentDisplay (CGDisplay.MainDisplayID);
});

[Test]
public void GetCurrentDisplayTest () => Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
Assert.AreEqual (CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay ());
});

[Test]
public void GetTypeIdTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
Assert.DoesNotThrow (() => {
CVDisplayLink.GetTypeId ();
}, "Throws");
}

[Test]
public void TryTranslateTimeValidTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
using var displayLink = new CVDisplayLink ();
displayLink.GetCurrentTime (out var timeStamp);
Assert.True (displayLink.TryTranslateTime (timeStamp, out var _));
}
}
}
#endif

0 comments on commit 94d8143

Please sign in to comment.